C#Json数据反序列化为Dictionary并根据关键字获取指定的值

Json数据:

{
  "dataSet": {
    "header": {
      "returnCode": "0", 
      "errorInfo": "HTTP请求错误", 
      "version": "V1.0R010", 
      "totalRows": "2000", 
      "returnRows": "20"
    }, 
    "fieldDefine": {
      "assetId": "string", 
      "serverIdcId": "int", 
      "inputTime": "datetime"
    }, 
    "data": {
      "row": [
        {
          "AssetId": "TCNS2006888", 
          "ServerIdcId": "1", 
          "InputTime": "2008-12-12"
        }, 
        {
          "AssetId": "TCNS2006889", 
          "ServerIdcId": "2", 
          "InputTime": "2008-1-1"
        }
      ]
    }
  }
}

将json数据转成dictionary的代码:

//实例化JavaScriptSerializer类的新实例
JavaScriptSerializer jss = new JavaScriptSerializer();

//将指定的 JSON 字符串转换为 Dictionary<string, object> 类型的对象
return jss.Deserialize<Dictionary<string, object>>(jsonData);

 

posted on 2015-08-05 09:06  狼来了  阅读(378)  评论(0编辑  收藏  举报