动态对象句柄问题Facebook C#SDK [英] dynamic object handle problem Facebook C# sdk

查看:97
本文介绍了动态对象句柄问题Facebook C#SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Facebook C#SDK用于桌面应用程序.我正在获取动态对象,然后提取名称,id等

I'm using Facebook C# sdk for desktop app. I'm getting the dynamic object and then extracting the name,id etc

dynamic result = fb.Get("/me");
string name=result.name;

现在的问题是我无法提取工作信息或喜欢的团队等.我已经使用了必需的权限,但是无法处理动态对象.格式如下:

Now problem is I can't extract the work information or favorite teams etc. I've used the required permissions, but unable to handle the dynamic object. It's in this format:

"languages": [
{
  "id": "106502622718539", 
  "name": "Bānglā"
}, 
{
  "id": "106059522759137", 
  "name": "English"
}

],

http://developers.facebook.com/tools/explorer/

尝试并进行了大量搜索以获取它们.一无所获.我读过它以数组的形式出现.请帮助通过C#代码提取这些信息.......

Tried and searched a lot to get them. Found nothing. I've read that it comes in the form of array. Please help to extract those information through C# code..........

推荐答案

这是如何在Facebook C#SDK/SimleJson中使用json数据的黄金法则(内部,Facebook C#SDK使用SimpleJson进行json序列化/反序列化 http://simplejson.codeplex.com/).

Here is a golden rule on how to consume json data in Facebook C# SDK/SimleJson (internally Facebook C# SDK uses SimpleJson for json serializing/deserializing http://simplejson.codeplex.com/).

共有3种可能的类型:数组,Json对象和私有类型.

There are 3 possible types: Array, Json Object and privimitive types.

  • 数组:可以转换为IList< Object>或IList< dynamic>
  • JsonObject :键值对-IDictionary<字符串,对象>
  • 原始类型:布尔型,字符串型,长整型和双精度型.
  • Array: Can be casted to IList<Object> or IList<dynamic>
  • JsonObject: key value pair - IDictionary<string, object>
  • primitive types: bool, string, long and double.

由于语言是一个数组,因此您可以将其用作IList< object>,并在Json Skeet提到的for循环中使用它.您还将获得IList< T>等其他功能的好处,例如索引器和数组的不同属性.

Since langauges is an array, you can use it as IList<object> and consume it in a for loop like mentioned by Json Skeet. You also get the benefit of other IList<T> features such as indexer and different properties of the array.

dynamic result = fb.Get("/me");
var langauges = result.languages;
var length = languages.Length;
var lang1 = languages[0];
var lang1Id = lang1["id"];
var lang1Name = lang1["name"];
var lang2 = langauges[1];
var lang2Id = lang2.id;
var lang2Name = lang2.name;

由于lang1和lang2是JsonObject,因此您可以像在IDictionary< string,object>中那样使用像lang1 ["id"]这样的索引器,也可以更轻松地使用lang1.id.

since lang1 and lang2 is a JsonObject you can either use indexer like lang1["id"] as you do in for IDictionary<string,object> or much easier use lang1.id.

这篇关于动态对象句柄问题Facebook C#SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆