2013-08-14 2 views
2
unity3d

에 minijson를 사용하여 값이 내가 사용어떻게 키와 내가 unity3d</p> <p>응답에서 JSON의 값을 얻을 수 minijson을 사용하고

{"existing":[{"LastUpdated":"7\/9\/2013 4:03:57 AM","LetterSpeed":100,"Letters":"SP","NumRandom":5,"Reward":10,"ShowWordDesc":false,"ShowWordHint":false,"Sort_ID":5,"WN_Level_ID":34,"WN_Word_ID":95,"WordDesc":"","WordHint":"","zError":null},{"LastUpdated":"7\/9\/2013 4:03:57 AM","LetterSpeed":100,"Letters":"aún","NumRandom":2,"Reward":10,"ShowWordDesc":true,"ShowWordHint":false,"Sort_ID":10,"WN_Level_ID":34,"WN_Word_ID":83,"WordDesc":"still","WordHint":"","zError":null},{"LastUpdated":"7\/9\/2013 4:03:58 AM","LetterSpeed":200,"Letters":"tanto","NumRandom":3,"Reward":10,"ShowWordDesc":true,"ShowWordHint":false,"Sort_ID":20,"WN_Level_ID":34,"WN_Word_ID":84,"WordDesc":"so","WordHint":"","zError":null}]} 

코드 모두가

using UnityEngine; 
using System.Collections; 
using System.Collections.Generic; 
using MiniJSON; 

입니다 인쇄 할 수 있습니다 기능 중

string response = www.text; 
Debug.Log(response);    
IDictionary search = (IDictionary) Json.Deserialize(response); 
IList tweets = (IList) search["existing"];  
foreach (IDictionary tweet in tweets) { 
    Debug.Log(tweet["LastUpdated"]);     
} 

키 이름을 모르는 경우 어떻게 키와 값을 모두 저장할 수 있습니까?

답변

0

하지 전적으로 당신이 여기 출력으로 얻을려고하지만 추측을한다면 다음 수행 할 작업을 확인하십시오

string response = www.text; 

Debug.Log(response); 

IDictionary search = (IDictionary) Json.Deserialize(response); 

IList tweets = (IList) search["existing"]; 

foreach (IDictionary tweet in tweets) { 
    Debug.Log("Tweet details:"); 
    foreach(KeyValuePair<string, string> tweetData in tweet) { 
     Debug.Log("Key = " + tweetData.Key.ToString() + 
        " Value = " + tweetData.Value.ToString()); 
    }    
} 
+0

는 유니티 디버그 로거를 위해 그것을 해결했습니다. –

+0

내 코드와 관련이 있다고 생각지 않습니까? 42 번 줄을 확인 했니? –

+0

foreach (KeyValuePair tweetData in tweet) {이 줄은 오류를 만듭니다. InvalidCastException : 원본 형식에서 대상 형식으로 캐스팅 할 수 없습니다. – Sona