unable to parse dictionary values

2019-09-08 11:13发布

问题:

I am trying to parse a dictionary from a json file as follows

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

At first i am unable to get the details of appname and taborder and my question regarding it is here . I got a solution for there and by implementing it i got the values of taborder and appname

In the same way i am trying to retrieve the value of a dictionary as follows

"home":{ "type":"grid", "items":[ "appointments", "reachus", ] }

Following is my piece of code

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);

how to get the values from the dictionary, pls help me

回答1:

try this class structure

 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;}
    }