. NET 2.0 uses the latest version of json.net for deserialization

Source: Internet
Author: User

We know that the latest version of json.net is based on. net 3.5 framework, how to make it work in. NET 2.0 framework, of course, is Google + Baidu, fortunately, finally found a solution in an English blog, the address is as follows: http://james.newtonking.com/archive/2009/08/02/net-2-0-support-added-to-json-net.aspx

This articleArticleDownload the latest JSON version. net source code (http://json.codeplex.com/), and then extract, src directory is its source code, we open newtonsoft. JSON. netmask SLN, Which is. NET 2.0 solution, and then compile, it passes smoothly, anyway, I did not encounter any special circumstances. After compilation, you will see a directory named dotnet20 in the bin \ release directory. Obviously, the json.net source code is quite good and has been written for us. the method to run in net2.0. You will find that there is an additional DLL file (linqbridge. dll) Here. What is the purpose of this? It is described in the article written by foreigners. in the net2.0 framework, I am not very familiar with this LINQ anyway. I don't care about it. If this component is useful, it will be useful. Next, copy linqbridge. DLL and newtonsoft. JSON. netbench DLL to json35r8 \ source \ tools \ ilmerge. The last step is poor. Open the CMD window and run the following command:

 
Ilmerge.exe/internalize/out: newtonsoft. JSON. netw.merged. dll newtonsoft. JSON. netw.dll linqbridge. dll

 

This will merge the two DLL into a DLLProgramIntroduce the merged DLL to use the latest JSON. Net version.

The following json.net instancesCodeWeb: http://www.java2s.com/Open-Source/CSharp/Development/Json.NET/Newtonsoft/Json/Tests/Serialization/JsonSerializerTest.cs.htm

 

My deserialization code:

 

Code

Public   Static Ilist < Searchresult > Getsearchlist ( String Jsons)
{

// Get JSON result objects into a list
Jobject o = (Jobject) jsonconvert. deserializeobject (jsons );

Jtoken torw.sarray = (Jtoken) O [ " Rules " ];

// Serialize JSON results into. Net objects
Ilist < Searchresult > Searchresults =   New List < Searchresult > ();
Searchresult C =   Null ;
Foreach (Jtoken result In Torw.sarray)
{
C =   New Searchresult ();
C. searchfield = Result. selecttoken ( " Field " ). Tostring (). Replace ( " \ "" , "" );
C. searchstring = Result. selecttoken ( " Data " ). Tostring (). Replace ( " \ "" , "" );
C. searchpipeline = Result. selecttoken ( " OP " ). Tostring (). Replace ( " \ "" , "" );

// Criterion searchresult = jsonconvert. deserializeobject <criterion> (result. tostring ());
Searchresults. Add (C );
}
 
Return Searchresults;
}

 

 

JSON:

{"AAA": "BBBB", "rules": [{"field": "XXXX", "data": "Ooooo", "op": "LT "}, {"field": "XXXX", "data": "Ooooo", "op": "GT" },{ "field": "xxyxx", "data ": "Ooooo", "op": "LTE"}]}

 

It's over. I don't understand it.

 

 

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.