parsing JSon

I am attempting to turn JSon data into data objects within my game. an example of the complexity of the data is as follows:

[{ “RECORDED_TIME” : 1.35604611843E12 , “APPDATA” : { “_id” : “1356046116848-e745d74f-068d-4f3d-a843-d1c285b9f2a5” , “created_at” : “2012-12-20T15:28:36Z” , “user_id” : “” , “session_date” : “2012-12-20” , “data” : { “ACCELEROMETER” : { “Z” : 7.748454570770264 , “Y” : 4.8307881355285645 , “X” : 0.16997157037258148} , “ORIENTATION” : { “Z” : 5.402302265167236 , “Y” : -37.40742492675781 , “X” : 230.08267211914062} , “LIGHT” : 316.14617919921875 , “BATTERY” : { “LEVEL” : 92 , “STATUS” : 2} , “SCREEN” : 1 , “MODEL” : “Galaxy Nexus” , “LOCALE” : { “LANGUAGE” : “English” , “COUNTRY” : “United States”} , “KEYLOCKED” : 0 , “TASKS” : [ “com.android.launcher” , “com.google.android.deskclock” , “com.google.android.browser” , “com.audible.application”] , “BLUETOOTH” : { “ENABLED” : 1 , “PAIREDDEVICES” : [ “BrainBand”]} , “WIFI” : { “ENABLED” : 0}}}},

{ “RECORDED_TIME” : 1.356046118449E12 , “APPDATA” : { “_id” : “1356046115820-23fa8359-3877-4b4c-b4ae-13e7496febfa” , “created_at” : “2012-12-20T15:28:35Z” , “user_id” : “” , “session_date” : “2012-12-20” , “data” : { “ACCELEROMETER” : { “Z” : 7.708956718444824 , “Y” : 4.909005641937256 , “X” : 0.41053903102874756} , “ORIENTATION” : { “Z” : 6.678679466247559 , “Y” : -36.089622497558594 , “X” : 235.98951721191406} , “LIGHT” : 311.1044006347656 , “BATTERY” : { “LEVEL” : 92 , “STATUS” : 2} , “SCREEN” : 1 , “MODEL” : “Galaxy Nexus” , “LOCALE” : { “LANGUAGE” : “English” , “COUNTRY” : “United States”} , “KEYLOCKED” : 0 , “TASKS” : [ “com.android.launcher” , “com.google.android.deskclock” , “com.google.android.browser” , “com.audible.application”] , “BLUETOOTH” : { “ENABLED” : 1 , “PAIREDDEVICES” : [ “BrainBand”]} , “WIFI” : { “ENABLED” : 0}}}}]

which is more easily read:

[
   {
      "RECORDED_TIME":1.35604611843E12,
      "APPDATA":{
         "_id":"1356046116848-e745d74f-068d-4f3d-a843-d1c285b9f2a5",
         "created_at":"2012-12-20T15:28:36Z",
         "user_id":"",
         "session_date":"2012-12-20",
         "data":{
            "ACCELEROMETER":{
               "Z":7.748454570770264,
               "Y":4.8307881355285645,
               "X":0.16997157037258148
            },
            "ORIENTATION":{
               "Z":5.402302265167236,
               "Y":-37.40742492675781,
               "X":230.08267211914062
            },
            "LIGHT":316.14617919921875,
            "BATTERY":{
               "LEVEL":92,
               "STATUS":2
            },
            "SCREEN":1,
            "MODEL":"Galaxy Nexus",
            "LOCALE":{
               "LANGUAGE":"English",
               "COUNTRY":"United States"
            },
            "KEYLOCKED":0,
            "TASKS":[
               "com.android.launcher",
               "com.google.android.deskclock",
               "com.google.android.browser",
               "com.audible.application"
            ],
            "BLUETOOTH":{
               "ENABLED":1,
               "PAIREDDEVICES":[
                  "BrainBand"
               ]
            },
            "WIFI":{
               "ENABLED":0
            }
         }
      }
   },
   {
      "RECORDED_TIME":1.356046118449E12,
      "APPDATA":{
         "_id":"1356046115820-23fa8359-3877-4b4c-b4ae-13e7496febfa",
         "created_at":"2012-12-20T15:28:35Z",
         "user_id":"",
         "session_date":"2012-12-20",
         "data":{
            "ACCELEROMETER":{
               "Z":7.708956718444824,
               "Y":4.909005641937256,
               "X":0.41053903102874756
            },
            "ORIENTATION":{
               "Z":6.678679466247559,
               "Y":-36.089622497558594,
               "X":235.98951721191406
            },
            "LIGHT":311.1044006347656,
            "BATTERY":{
               "LEVEL":92,
               "STATUS":2
            },
            "SCREEN":1,
            "MODEL":"Galaxy Nexus",
            "LOCALE":{
               "LANGUAGE":"English",
               "COUNTRY":"United States"
            },
            "KEYLOCKED":0,
            "TASKS":[
               "com.android.launcher",
               "com.google.android.deskclock",
               "com.google.android.browser",
               "com.audible.application"
            ],
            "BLUETOOTH":{
               "ENABLED":1,
               "PAIREDDEVICES":[
                  "BrainBand"
               ]
            },
            "WIFI":{
               "ENABLED":0
            }
         }
      }
   }
]

I am trying to use the JSon script found here I see the data is being placed into the node object, but it would seem that all of the data of the string is being placed there even if it is multiple JSon objects, and all that is changing is the formatting, and the test suggested by Bunny83 here does not work, but I am able to output the results of the parse through

// data is the inputted JSon data (tested from file, and from website)
var testData = JSON.Parse(data);
Debug.Log(testData);

I am not sure what part is going wrong, but I don’t know what is happening. to recreate place JSon data into Resouces/dataFile.txt, and the following class:

using UnityEngine;
using System.IO;
using System.Collections;
using SimpleJSON;

public class DisplayData : MonoBehaviour {

    public JSONNode testData;

    public TextAsset file;

    private string fileName = "dataFile";

    void Start()
    {
        // get data from file
        file = (TextAsset) Resources.Load(fileName);
        if (file == null)
        {
            Debug.Log("file not loaded");
        }
        else 
        {
            Debug.Log("File Exists"); 
			Debug.Log(file.text);
            testData = ProcessInboundData(file.text);
			Debug.Log(testData);
        }
        if (testData["success"] == "1")
        {
            Debug.Log("processing success");
        } else
        {
            Debug.Log("processing failed");
        }
        Debug.Log("StartAfterCo");
    }
	
	void OnGUI()
	{
		GUI.TextArea(new Rect(0,0,800,600), testData.ToString());
	}
	
    JSONNode ProcessInboundData(string data)
    {
        JSONNode json = JSON.Parse(data);
        return json;
    }
}

Well, if you parse this JSON string you will get an array as root node. The array will contain 2 elements in this case.

So to access the first object in the array you write:

    testData[0]...

This will read the “_id” field of the “APPDATA” object in the first object:

    string id = testData[0]["APPDATA"]["_id"];
    // id should contain "1356046116848-e745d74f-068d-4f3d-a843-d1c285b9f2a5"
    
    double x = testData[0]["APPDATA"]["data"]["ACCELEROMETER"]["Z"].AsDouble;
    // x should contain 0.16997157037258148
    // note that a float has less digits than a double and this number would
    // be truncated / rounded when converted / stored in a float variable.

    string task2 = testData[0]["APPDATA"]["data"]["TASKS"][1];
    // task2 should contain "com.google.android.deskclock"

Mono /.NET (CIL) is a compiled language and doesn’t support creating any dynamic types. So you can’t simply turn it into a C# class since you have to declare every type in C# itself.