Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

JSON Decode problem

Discussion in 'Scripting' started by Dzxyan, Jul 3, 2014.

  1. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
    I wanna ask how to decode the JSON data?
    And i have a JSON data like this,
    how to decode it?

    Code (CSharp):
    1. string JsonData = "{\"Version\":\"1.0.0\",\"Username\":\"Dzxyan\",\"CurrencyTable\":[{\"Currency\":1,\"Rate\":2},{\"Currency\":2,\"Rate\":3,{\"Currency\":3,\"Rate\":5}, }";
    hope anyone can help it,
    i really rush for that.
    Thanks
     
  2. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    SimpleJSON is pretty good. I am using that myself.
     
  3. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
    ya, i see it,
    but i don't really know how decode the data that i provide,
    any help?
     
  4. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
    I have fix the main deserialize
    but face another problem
    if inside the rate
    Code (CSharp):
    1. string JsonData = "{\"Version\":\"1.0.0\",\"Username\":\"Dzxyan\",\"CurrencyTable\":[{\"Currency\":1,\"Rate\":2},{\"Currency\":2,\"Rate\":3},{\"Currency\":3,\"Rate\":5}, }";
    become this
    Code (CSharp):
    1. \"Rate\":[1,2,3,4,5]
    I cant get the value how?
     
  5. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    Code (csharp):
    1.  
    2. var parsed_data = JSON.Parse(JsonData);
    3.  
    4. for(var x = 0; x < parsed_data["Rate"].Count; x++)
    5. {
    6.       Debug.Log(parsed_data["Rate"][x]);
    7. }
    8.  
    Is this what you mean?
     
  6. Dzxyan

    Dzxyan

    Joined:
    Sep 23, 2013
    Posts:
    167
    Thanks god!
    You save my day!
    THANKS!!