开发者

How to parse JSON data

开发者 https://www.devze.com 2023-03-06 19:45 出处:网络
Can anyone tell me how I can parse this data in WCF Service with C#? {\"syncresp\": { \"synchdr\": {开发者_Go百科

Can anyone tell me how I can parse this data in WCF Service with C#?

{"syncresp": {

  "synchdr": {开发者_Go百科

    "sessionref": "1234567890"                 
    "syncref": "20110327T012000"                         

  },

  "syncbody": {

    "syncedrecs": [
      {
        "recloc": "plog,0,123",
      },
       {
        "recloc": "plog,0,123",
      }
    ],
    "serverdata": [

      {
        "table": " book",
        "action": "new",
        "recdata": {
          "pnum": "67890",
          "fname": "ghgfhn"
          "lname": "M"
          .
          .
          .
        },
      },

      {
        "table": "pins",
        "action": "new",
        "recdata": {
         "patid": 123,
          "insprovid": 5,
          "insnum": "X34567",
          "effdate": "6/3/2011",
          "expdate": "5/3/2012",
          "status": "a",
        },
      },
    ]    
  }
}}


If you want to create a data contract which can be used in WCF to consume / generate this kind of data, then take a look at http://blogs.msdn.com/b/carlosfigueira/archive/2011/01/11/inferring-schemas-for-json.aspx - it has a tool which "infers" the corresponding classes which can be used, with the DataContractJsonSerializer, to serialize / deserialize your example.


This is quite simple question, so read some manuals before asking such questions. First search result in google:

http://blah.winsmarts.com/2009-12-How_to_parse_JSON_from_C-.aspx

JavaScriptSerializer jSerialize = new JavaScriptSerializer();
BusinessObjectType businessObject = jSerialize.Deserialize<BusinessObjectType>(configuration);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号