Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

unity get json value

You can use LitJson, it is easy to use and easy to install.

Go to this link and download and import the .unitypackage into Unity:
https://github.com/Mervill/UnityLitJson

Demo code (c#):

using LitJson;

public class myClass : MonoBehaviour
{
	private void Start()
    {
    	string jsonString = "{ "distanceThisMonth": { "jeff": 56, "lizibod": "206.02" }, "distanceThisWeek": { "jeff": 13, "lizibod": "37.36" }, "stepsThisMonth": { "jeff": 94838434, "lizibod": "316812" }, "stepsThisWeek": { "jeff": 235642, "lizibod": "57331" } }";
    
    	JsonData json = JsonMapper.ToObject(a JSON string);
        
        Debug.Log(json["distanceThisMonth"]["jeff"].ToString()); //returns 56
        Debug.Log(json["stepsThisMonth"][1].ToString()); //returns 316812
    }
}
 
PREVIOUS NEXT
Tagged: #unity #json
ADD COMMENT
Topic
Name
1+5 =