Irregular JSON parsing (i)

Source: Internet
Author: User

Tag: Indicates color REAC use to remove str key value Dex

The following data structures are available:

{   "orderId": "000001" ,   "goodsId[0]" : "001" ,   "goodsId[2]" : "002" ,   "goodsId[3]" : "003" , }

Goodsid is infinitely extended, ask how to parse.

Obviously, the idea of defining a class and then parsing will certainly not work, i.e. using dynamic (without defining an entity class, directly taking the value of the corresponding key), such as: Dynamic obj = Jsonconvert.deserializeobject (JSON); This is also not possible, because Obj.orderid can express, but the back of the with [], cannot be removed.

So we have to change the idea. The corresponding value is obtained by converting to the attribute property of the Jobject object, so the code is as follows.

string " {\ "orderid\": \ "000001\", \ "goodsid[0]\": \ "001\", \ "goodsid[3]\": \ "003\", \ "goodsid[10]\": \ "New Data\"} "    as foreach (Var in jsonobj.properties (). ToArray ())     Console.WriteLine ("key={0}, value={1}",         p.name , Jsonobj[p.name]. Value<string> ());

Irregular JSON parsing (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.