https://www.cnblogs.com/zjoch/p/4458516.html
  •  
    • 再来我们要怎么解析JSON格示呢?在.net 中,我们很孰悉的JSON.net,没错,我们依然可以在Xamarin中使用他

      感谢社群伟大的贡献 下载网址: http://components.xamarin.com/view/json.net/

      接续上一个项目我们多引入下载后的 Newtonsoft.Json.dll

      记得要引入Android 下的

      引入后就跟我们平常使用JSON.net 一样首先我们要为Facebook接回来的数据建立一个相对应的Class

      这时候我们可以使用 http://json2csharp.com/ 这网站帮忙

      在项目中建立一个User 的Class

      01.namespace SampleForWebClient
      02.{
      03.public class User
      04.{
      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.}

      我们回到主程序

      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 SampleForWebClient
      07.{
      08.[Activity(Label = "Json.net测试", MainLauncher = true, Icon = "@drawable/icon")]
      09.public class Activity1 : Activity
      10.{
      11.protected override void OnCreate(Bundle bundle)
      12.{
      13.base.OnCreate(bundle);
      14. 
      15.// Set our view from the "main" layout resource
      16.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 name
      30.Toast.MakeText(this, user.id+":"+user.name, ToastLength.Long).Show();
      31.}
      32. 
      33. 
      34.}
      35.}

      结果:

      是不是很简单,在Xamarin 下面开发Android 跟过去的体验是相同的

最新文章

  1. Android下的屏幕适配
  2. word常用操作
  3. uglifyjs压缩JS的
  4. Swift定义单例
  5. 《ASP.NET MVC4 WEB编程》学习笔记------ViewBag、ViewData和TempData的使用和区别
  6. Android 开发-Intent传递普通字符串
  7. codeforces 192a
  8. vs2005_the breakpoint will not currently be hit. The source code is different from the original verison.
  9. MultiWii MWC的软件和调试方法
  10. View not attached to window manager crash 的解决办法
  11. html+js+ashx+easyui+ado.net权限管理系统
  12. Android 5.x 权限问题解决方法
  13. \r,\n,\r\n的区别和用法
  14. nohup ./startWebLogic.sh &gt;out.log 2&gt;&amp;1 &amp; 解析
  15. [BZOJ2457][BeiJing2011]双端队列 (单调性)
  16. 调用Android自带浏览器打开网页
  17. Linux git 在自己的服务器上建立 git 仓库(repository)
  18. [UE4]Spacer
  19. 剖析QMenu &amp; Qt完全定制化菜单
  20. R实战 第十篇:列联表和频数表

热门文章

  1. 强大的MobaXterm
  2. eclipse和myeclipse中将项目发布到tomcat的root目录
  3. Python的Web应用框架--Django
  4. Foxmail 7.0破解版,拷贝到新机器后,发送邮件乱码问题
  5. AspNet Core :创建自定义 EF Core 链接数据库
  6. python 3.6 MJ小工具
  7. 使用python处理excle表格
  8. 【Win 10 应用开发】MIDI 音乐合成——乐理篇
  9. HDU 4193 Non-negative Partial Sums(想法题,单调队列)
  10. 7、创建ROS msg和srv