Xamarin calls Json.NET to parse JSON

Source: Internet
Author: User


    • How are we going to parse the JSON grid? In. NET, we are the json.net, yes, we can still use him in Xamarin

      Thanks to the community for its great contribution download URL: http://components.xamarin.com/view/json.net/


      Continue on the previous project we introduced the download Newtonsoft.Json.dll


      Remember to introduce Android under the


      As we normally use json.net, we'll start by creating a corresponding class for the data that we've taken back from Facebook.

      At this time we can use http://json2csharp.com/this website to help


      Create a user class in the project

      View Sourceprint?01.namespace SampleForWebClient02.{03.public class User04.{05.public string id { getset; }06.public string name { getset; }07.public string first_name { getset; }08.public string last_name { getset; }09.public string link { getset; }10.public string username { getset; }11.public string gender { getset; }12.public string locale { getset; }13.}14.}

      We go back to the main program

      View Sourceprint?01.using <a href="http://www.it165.net/pro/ydad/" target="_blank" class="keylink">Android</a>.App;02.using Android.Widget;03.using Android.OS;04.using Newtonsoft.Json;05. 06.namespace SampleForWebClient07.{08.[Activity(Label = "Json.net测试", MainLauncher = true, Icon = "@drawable/icon")]09.public class Activity1 : Activity10.{11.protected override void OnCreate(Bundle bundle)12.{13.base.OnCreate(bundle);14. 15.// Set our view from the "main" layout resource16.SetContentView(Resource.Layout.Main);17. 18.var btnGetData1 = FindViewById<Button>(Resource.Id.btnGetData1);19. 20.btnGetData1.Click += btnGetData1_Click;21.}22. 23.void btnGetData1_Click(object sender, System.EventArgs e)24.{25.var webClient = new System.Net.WebClient();26.var result = webClient.DownloadString("https://graph.facebook.com/donma.hsu");27.//透过JSON.net 反序列化为User对象28.var user = JsonConvert.DeserializeObject<User>(result);29.//印出 id and name30.Toast.MakeText(this, user.id+":"+user.name, ToastLength.Long).Show();31.}32. 33. 34.}35.}

      Results:


      is not very simple, under Xamarin development Android and the past experience is the same

Xamarin calls Json.NET to parse JSON

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.