x1137730260
x1137730260
2015-01-15 06:46
采纳率: 100%
浏览 4.9k

C#,没有key只有value的JSON串,如何转换为list<T>

[]里面的JSON没有key只有value

Infor:{"tradeCode":"5040010","mess":"成功","data":[["801","玉璜","2114-10-01","订单","5.29","3.91","100%","100%","0.15%","0.0%","香港","香

港","1.00","1","0","0","0.00","0.0","0.0","0.0"],["802","双龙玉璜","2114-10-01","订单","5.17","3.82","100%","100%","0.15%","0.0%","香港","香

港","1.00","1","0","0","0.00","0.0","0.0","0.0"],["803","龙凤玉佩","2114-10-14","订单","2.32","1.72","100%","100%","0.3%","0.0%","香港","香

港","0.01","1","0","0","0.00","0.0","0.0","0.0"],["805","古玉屏风","2114-11-11","订单","1.97","1.45","100%","100%","0.3%","0.0%","香港","香

港","0.01","1","0","0","0.00","0.0","0.0","0.0"],["806","古玉玉龙","2114-12-18","订单","2.64","1.95","100%","100%","0.3%","0.0%","香港","香

港","0.01","1","0","0","0.00","0.0","0.0","0.0"]],"sid":"M74W4OIDTICHQ9AUE3NLRVGG90KUHFHT","ver":"1.0.0","zip":"n","charset":"UTF-

8","encrypt":"0","cryptKey":null,"digest":"","packetNo":1,"packetCounts":1,"returned":false}

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • showbo
    已采纳

     List<string>
    

    对象,下面是居于Newtonsoft.Json.Net20.dll类库的

     using System;
    using System.Collections.Generic;
    using Newtonsoft.Json;
    public class ClsInfor
    {
        public string tradeCode, mess;//其他的属性。。自己加
        public List<List<string>> data;
    }
    public class MyJson { public ClsInfor infor;}
    
      string s="{ Infor: { \"tradeCode\": \"5040010\", \"mess\": \"成功\", \"data\": [[\"801\", \"玉璜\", \"2114-10-01\", \"订单\", \"5.29\", \"3.91\", \"100%\", \"100%\", \"0.15%\", \"0.0%\", \"香港\", \"香港\", \"1.00\", \"1\", \"0\", \"0\", \"0.00\", \"0.0\", \"0.0\", \"0.0\"], [\"802\", \"双龙玉璜\", \"2114-10-01\", \"订单\", \"5.17\", \"3.82\", \"100%\", \"100%\", \"0.15%\", \"0.0%\", \"香港\", \"香港\", \"1.00\", \"1\", \"0\", \"0\", \"0.00\", \"0.0\", \"0.0\", \"0.0\"], [\"803\", \"龙凤玉佩\", \"2114-10-14\", \"订单\", \"2.32\", \"1.72\", \"100%\", \"100%\", \"0.3%\", \"0.0%\", \"香港\", \"香港\", \"0.01\", \"1\", \"0\", \"0\", \"0.00\", \"0.0\", \"0.0\", \"0.0\"], [\"805\", \"古玉屏风\", \"2114-11-11\", \"订单\", \"1.97\", \"1.45\", \"100%\", \"100%\", \"0.3%\", \"0.0%\", \"香港\", \"香港\", \"0.01\", \"1\", \"0\", \"0\", \"0.00\", \"0.0\", \"0.0\", \"0.0\"], [\"806\", \"古玉玉龙\", \"2114-12-18\", \"订单\", \"2.64\", \"1.95\", \"100%\", \"100%\", \"0.3%\", \"0.0%\", \"香港\", \"香港\", \"0.01\", \"1\", \"0\", \"0\", \"0.00\", \"0.0\", \"0.0\", \"0.0\"]], \"sid\": \"M74W4OIDTICHQ9AUE3NLRVGG90KUHFHT\", \"ver\": \"1.0.0\", \"zip\": \"n\", \"charset\": \"UTF-8\", \"encrypt\": \"0\", \"cryptKey\": null, \"digest\": \"\", \"packetNo\": 1, \"packetCounts\": 1, \"returned\": false} }";
            MyJson o = JsonConvert.DeserializeObject(s,typeof(MyJson)) as MyJson;
            Response.Write(o == null); 
            ClsInfor infor = o.infor;
            Response.Write(infor.mess + "<BR>"); 
            foreach (List<string> list in infor.data)
            {
                Response.Write(string.Join(",", list.ToArray()) + "<br>");
            }
    
    点赞 评论
  • Tiger_Zhao
    Tiger_Zhao 2015-01-15 07:25

    JSON里面有key的叫字典,没key的叫数组。
    如果你非得在C#中统一成字典,可以考虑用下标 0,1,2... 做key。

    点赞 评论

相关推荐