Parse. NET Json to Dictionary, native code

Source: Internet
Author: User

I have been using the Json that comes with Microsoft, and I have been trying to parse the Json myself. So I spent one night writing a parsing class,

 

Let's start with the following ideas: for example, the standard JSon format is {"Key": "Value1", "Key2": 1, "Key3": [1, 2, 3, 4], "Key4": {"Test1": "2"}, "Key5": [{"A": 1, "B": 2}]}

In this way, I regard the content of {} as a complete object. When I encounter {}, I treat it as a complete object parsing (I may have a problem with my ability to express it, but I cannot express it too much)

First of all, the Key must contain double quotation marks in strict format of the read Key, but it is not excluded. So I made a judgment that if there is double quotation marks, the Key will be removed, and then the value will be the value, the Value can be roughly divided into three types,

A common value is a string, number, or time,

The second is the complete class,

Array is the third type, but Arrays can also be divided into two types, one is a normal array and the other is an array of the tape class,

After testing the performance, I feel okay.

Don't talk about it.

Declare EndCount = Dictionary <,> JsonReader (TextReader reader, endCount = myObjDate = Dictionary <,> myReader = EndCount = intByte = (EndCount! = & IntByte! =-Key = value = (EndCount =) {intByte =: (reader, JsonReader (: (StringReader (value ), intByte = (intByte = EndCount ++ (intByte = EndCount -- ReadKeyName (StringBuilder strBuilder = intByte = (intByte = lastIntByte =-endByteInt =-(intByte = -( intByte = | intByte = endByteInt = intByte = (intByte! =-(EndByteInt! =-(IntByte = endByteInt & lastIntByte! = (IntByte = strBuilder. append (intByte = item = JsonReader (myReader, (intByte = ReadValueArrayString (StringBuilder strBuilder = intByte = (intByte = lastIntByte =-bytes =-(intByte = | intByte = bytes = intByte = (intByte! =-LastChar = (endByteInt! =-(IntByte = endByteInt & lastIntByte! = (IntByte ==|| (intByte ==& lastIntByte! = StrBuilder. append (intByte = ReadValueString (StringBuilder strBuilder = intByte = (intByte = lastIntByte =-endByteInt =-(intByte = | intByte = bytes = intByte = (intByte! =-(EndByteInt! =-(IntByte = endByteInt & lastIntByte! = (IntByte ==|| (intByte ==& lastIntByte! = StrBuilder. Append (intByte = List <> list = List <> intByte = (intByte! = (IntByte = item = JsonReader (myReader, (ReadInt () = (intByte = list. Add (ReadValueArrayString (intByte =) {intByte =}

 

Related Article

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.