VisualStudio2012 easily convert JSON data to Poco code

Source: Internet
Author: User

Original: VisualStudio2012 easily convert JSON data to Poco code

In Visual Studio 2012, it's easy to convert JSON data into Poco code, first you need to install Web Essentials 2012. In VS2012, the right-click menu in any CS file appears:


With this http://channel9.msdn.com/niners/CapSoft/achievements/visualstudio?json=true&raw=true URL as an example, the request will return the JSON data :

{"Name": "Capsoft", "FriendlyName": "Jphellemons", "achievements": [{"Name": "Morethan10stepover", "Currentnumber": 11 , "dateearned": "2012-08-22t14:00:23.9742427+02:00"},{"Name": "Usedorganizedusings50achievement", "CurrentNumber" : 3},{"name": "Regions10achievement", "dateearned": "2012-01-19t16:04:10.7662105+01:00"},{"name": " Closeallbutthis10achievement "," Currentnumber ": 8},{" Name ":" Morethan10stepinto "," Currentnumber ": One," DateEarned ": "2012-08-22t14:00:21.8049672+02:00"},{"Name": "ExtensionsAchievement5", "dateearned": "2012-03-15t09 : 37:43.3473414+01:00 "},{" Name ":" ExtensionsAchievement10 "," dateearned ":" 2012-03-15t09:37:43.5283517+01:00 "},{" Name ":" Installandregisterforachievements "," dateearned ":" 2012-03-15t09:37:43.7173626+01:00 "},{" name ":" Bravenewworldachievement "," dateearned ":" 2012-08-22t14:43:54.1176689+02:00 "},{" Name ":" ReferencedAssemblies25 "," Dateearned ":" 2012-08-22t14:44:54.1723276+02:00 "},{" Name ":" Morethan1000loc "," dateearned ":" 2012-08-23t09 : 39:37.8062693+02:00 "},{" Name ":" Morethan30enumfieldsachievEment "," dateearned ":" 2012-08-23t09:39:44.3466433+02:00 "},{" Name ":" Longerthan300locachievement "," DateEarned ":" 2012-08-23t09:39:44.6546610+02:00 "},{" Name ":" Equalopportunistachievement "," dateearned ":" 2012-08-23t09 : 39:44.7196647+02:00 "},{" name ":" Gotoachievement "," dateearned ":" 2012-08-28t09:55:57.0744434+02:00 "},{" name ":" Morethan10overloadsachievement "," dateearned ":" 2012-08-29t15:08:46.8305656+02:00 "}]}
Copy these data clips, execute "Paste JSON as Classes", and in the IDE we'll generate code like this:




     Public class Achievement
    {
         Public string Name {get; set;}
         Public int  Public DateTime dateearned {get; set;}
    }
     Public class Parent
    {
         Public string Name {get; set;}
         Public string  Public Achievement[] Achievements {get; set;}
    }
  We haven't written any code yet, so we're going to install a Json.NET class library from NuGet and get the data objects easily with the following three lines of code:


      New WebClient ();   
      string json = WC. Downloadstring ("Http://channel9.msdn.com/niners/CapSoft/achievements/visualstudio?json=true&raw=true" );    
      var data = jsonconvert.deserializeobject<parent> (JSON);


Well, so far, it's been easier to encode, and we can actually process JSONP data and hopefully help you with your development.


Petter Liu
Source: http://www.cnblogs.com/wintersun/
This copyright belongs to the author and the blog Garden altogether, welcome reprint, However, without the author's consent, this statement must be retained, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.
This article is also published in my standalone blog-petter Liu blog.

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.