本文使用的Json库为Newtonsoft.Json
接收到的json数据如下:
{"errcode":0,"errmsg":""," data":{ "show_msg":1, "show_errmsg":1, "config":{"1":50,"2":1,"3":10,"4":1000,"5":100,"6":1,"7":500}}}
接收时使用的对象如下:
public class S_Common_Data<T> { public int errcode = -1; public string errmsg; public T data; } public class S_Permission_Data { public int show_msg; public int show_errmsg; public IDictionary<string, string> config; }
序列化时的调用为:
S_Common_Data<S_Permission_Data> data = JsonConvert.DeserializeObject<S_Common_Data<S_Permission_Data>>(json);
即可将config里的纯数字key以字典的形式输出,当然如果可以保证一定是数字,也可以把key值用int类型来接收。
标签:show,C#,int,Json,key,public,errmsg From: https://www.cnblogs.com/vsirWaiter/p/17151481.html