2013-09-02 5 views
1
The Code like this: 
string jsonString = "{ \"array\": [[1.44,22,33], [1.445,2222,3333]]" + 
        "\"object\": {\"key1\":\"value1\", \"key2\":256}, " + 
        "\"string\": \"The quick brown fox \\\"jumps\\\" over the lazy dog \", " + 
        "\"unicode\": \"\\u3041 Men\\u00fa sesi\\u00f3n\", " + 
        "\"int\": 65536, " + 
        "\"float\": 3.1415926, " + 
        "\"bool\": true, " + 
        "\"null\": null }"; 

//Dictionary<string, object> dict = MiniJSON.LC_MiniJson.Deserialize(jsonString) as Dictionary.<string. Object>; 
Dictionary<string, object> dict = MiniJSON.LC_MiniJson.Deserialize(jsonString) as Dictionary<string, object>; 
Debug.Log("deserialized: " + dict.GetType()); 
//List<object> lst = (dict["array"]) as List<object>; 

Debug.Log("dict['array'][0]: " + (((dict["array"]) as List<object>)[0])); 
Debug.Log("dict['string']: " + dict["string"].ToString()); 
Debug.Log("dict['float']: " + dict["float"]); // floats come out as doubles 
Debug.Log("dict['int']: " + dict["int"]); // ints come out as longs 
Debug.Log("dict['unicode']: " + dict["unicode"].ToString()); 

Dictionary<string, object> dict2 = (dict["object"]) as Dictionary<string, object>; 

string str = MiniJSON.LC_MiniJson.Serialize(dict2); 

이제 "array"값을 얻고 싶습니다. 나는 minijson을 사용하는 법을 알지 못합니다. 누가 경험 했습니까?Unity3d에서 MiniJson을 사용하는 방법?

답변

1

답변은 코드에 있습니다.

((dict["array"]) as List<object>)[0] 

이 값은 배열에서 반환됩니다. 당신이 목록을 만들려면 , 당신은 할 수 있습니다 :

var dict = Json.Deserialize(jsonString) as Dictionary.<String,System.Object>; 

var arrayList = new List.<System.Object>(); 
arrayList = ((dict["array"]) as List.<System.Object>); 

Debug.Log("array[0]: "+arrayList[0]); 

은 또한 단지와 같은 자바 스크립트에서 같은 변수에 액세스 할 수 있습니다 Debug.Log(data.array[0]); Debug.Log(data.object.key1);,하지만 당신은 그 JSON 문자열을위한 클래스를 작성해야합니다. 참조 : https://gist.github.com/Edudjr/cb407c67e76ac36bcfac#file-classminijson-js

관련 문제