无法解析字典值

时间:2012-07-11 09:56:17

标签: json windows-phone-7

我正在尝试从json文件解析字典,如下所示

{
    "appname":"App Name",
    "taborder":[
                "Street",
                "Country"
                ],
    "home":{
        "type":"grid",
        "items":[
                 "Street",
                 "Country"
                 ]
        }
}

首先,我无法获得appnametaborder的详细信息,我的问题是here。我在那里得到了一个解决方案,通过实现它,我获得了taborder and appname

的值

以同样的方式我试图检索字典的值如下

“家”:{         “类型”:“网格”,         “项目”:                  “约会”,                  “reachus”                  ]         }

以下是我的代码

public class JavaScriptRequest
    {
        public string appname { get; set; }
        public List<string> taborder { get; set; }
        public Dictionary<string, string> home { get; set; }
    }

    JavaScriptRequest obj = DeserializeJavaScriptRequest(typeof(JavaScriptRequest), contents) as JavaScriptRequest;
    MessageBox.Show(obj.appname+obj.home);

如何从字典中获取值,请帮助我

1 个答案:

答案 0 :(得分:0)

尝试这个类结构

 public class JavaScriptRequest
    {
        public string appname { get; set; }
        public string[] taborder { get; set; }
        public JavaScriptRequest1 home { get; set; }

    }
    public class JavaScriptRequest1
    {
        public string type{get;set;}
        public string[] items{get;set;}
    }