2

我正在使用 minijson 从 unity3d 中的 json 获取值

回应是

{"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"]);                
} 

如果我不知道键名,我该如何保存键和值?

4

1 回答 1

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());
    }            
}
于 2013-08-14T05:33:56.073 回答