- Home /
Question by
mdagreda · Jan 19, 2013 at 12:59 AM ·
jsonconversionnumbers
How do I get a number out of a JSON file with JSONObject.cs
I am trying to get a number from a JSON file using JSONObject.cs from the unity [wiki][1] but I'm having some trouble. I am able to print the number from the json file using JSONObject.cs but saving that number in a variable is not working because unity says that the thing I have been printing is a JSONObject not a number. So here is some of my code if it helps.
var cParsedData: JSONObject = new JSONObject(textStringData);
print(cParsedData[0][s][attributePos);//this prints a number
var tempNum: double = cParsedData[0][0][attributePos].double;
Any ideas? [1]: http://wiki.unity3d.com/index.php/JSONObject
Comment
actually unity says that NullReferenceException: Object reference not set to an instance of an object on the third line
Best Answer
Answer by Bunny83 · Jan 19, 2013 at 01:39 AM
If you are sure it's a number, just assign it to the double variable. The value should be implicitly casted:
var tempNum: double = cParsedData[0][0][attributePos];