Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在unity3d中使用minijson打印键和值_C#_Json_Unity3d_Monodevelop - Fatal编程技术网

C# 如何在unity3d中使用minijson打印键和值

C# 如何在unity3d中使用minijson打印键和值,c#,json,unity3d,monodevelop,C#,Json,Unity3d,Monodevelop,我使用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":"","Word

我使用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"]);                
} 

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

不完全确定您试图在此处获得什么作为输出,但如果我猜测您希望执行以下操作:

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());
    }            
}
string response=www.text;
Debug.Log(响应);
IDictionary search=(IDictionary)Json.Deserialize(响应);
IList tweets=(IList)搜索[“现有”];
foreach(tweets中的索引tweet){
Log(“Tweet详细信息:”);
foreach(tweet中的KeyValuePair tweetData){
Debug.Log(“Key=“+tweetData.Key.ToString())+
“Value=“+tweetData.Value.ToString());
}            
}

为Unity调试记录器修复了它。我认为这与我的代码无关?你有没有检查第42行是什么?foreach(tweet中的KeyValuePair tweetData){这行代码产生错误:InvalidCastException:无法从源类型强制转换到目标类型。我在这里进行盲操作。您需要确保KeyValuePair的字符串、字符串部分与tweetData的字典类型匹配。它可能是:KeyValuePairtried,但有相同的错误。我给出了有问题的响应。这有助于您查找我的错误