日期:2014-05-17  浏览次数:20612 次

请问C#后台如何解析JSON
 我得到 的json 格式是  {"errorCode":"0","errorMessage":"","data":"hMGoq65YJmjBJwvbYoDr4XsUPg5tvbaN3SY26UM4cViRo8jkG5v6C1rlRMs23mZg"}

 请问如何从后台得到 data:后面的值

 还一个json: [{"productId":"test12560003","itemId":"125600030001","supplyPrice":999.99,"marketPrice":1000.99,"sellPrice":1000.99},{"productId":"thisisatestdata","itemId":"thisisatestdata7","supplyPrice":69.88,"marketPrice":70.88,"sellPrice":70.88}]

有2个JSON 怎么循环获得值  谢谢请指教

------解决方案--------------------
下载 Newtonsoft.Json.dll
------解决方案--------------------
楼上说的网址:     http://james.newtonking.com/json

很简单,一看就会
------解决方案--------------------
Newtonsoft.Json.dll 
里面有解析json的方法
------解决方案--------------------
下载Newtonsoft.Json.dll,引用合适的版本的dll。http://download.csdn.net/detail/guwei4037/5853053
代码:
class Program
    {
        public static void Main(string[] args)
        {
            string json1 = "{\"errorCode\":\"0\",\"errorMessage\":\"\",\"data\":\"hMGoq65YJmjBJwvbYoDr4XsUPg5tvbaN3SY26UM4cViRo8jkG5v6C1rlRMs23mZg\"}";

            Data1 data1 = JsonConvert.DeserializeObject<Data1>(json1);

            Console.WriteLine(string.Join(",", data1.ErrorCode, data1.ErrorMessage, data1.Data));

            string json2 = "[{\"productId\":\"test12560003\",\"itemId\":\"125600030001\",\"supplyPrice\":999.99,\"marketPrice\":1000.99,\"sellPrice\":1000.99},{\"productId\":\"thisisatestdata\",\"itemId\":\"thisisatestdata7\",\"supplyPrice\":69.88,\"marketPrice\":70.88,\"sellPrice\":70.88}]";

            List<Data2> list = JsonConvert.DeserializeObject<List<Data2>>(json2);

            foreach (var item in list)
            {
                Console.WriteLine(string.Join(",", item.ProductId, item.ItemId, item.SupplyPrice, item.MarketPrice, item.SellPrice));
            }
        }
    }

    public class Data1
    {
        public string ErrorCode { get; set; }
        public string ErrorMessage { get; set; }
        public string Data { get; set; }
    }

    public class Data2
    {
        public string ProductId { get; set; }

        public string ItemId { get; set; }

        publ