访问 facebook sdk api 返回的动态对象的属性
我使用以下代码从 FB 获取一些数据:
dynamic parameters = new ExpandoObject();
parameters.ids = "me";
parameters.fields = "friends";
dynamic result = fbApp.Api(parameters);
foreach (dynamic item in result)
{
Response.Write("<h1>" + item.name + "</h1>");
}
此代码失败,显然无法访问属性名称,这是错误:
'System.Collections.Generic.KeyValuePair<string,object>' does not contain a definition for 'name'
访问属性时我做错了什么?这不是正确的做法吗?
查询返回我想要的信息,只是无法访问它。浏览器中的查询正在返回:
{
"data": [
{
"name": "John Doe 1 ",
"id": "123456789"
},
{
"name": "John Doe 1 ",
"id": "123456789"
},
{
"name": "John Doe 1 ",
"id": "123456789"
}
]
}
任何帮助将不胜感激!
蒂亚!
I'm fetching some data from FB using the following code:
dynamic parameters = new ExpandoObject();
parameters.ids = "me";
parameters.fields = "friends";
dynamic result = fbApp.Api(parameters);
foreach (dynamic item in result)
{
Response.Write("<h1>" + item.name + "</h1>");
}
This code fails, apparently the property name cannot be accessed, here's the error:
'System.Collections.Generic.KeyValuePair<string,object>' does not contain a definition for 'name'
What i'm doing wrong when accessing the properties? Isn't this the correct way to do so?
The query returns the info i want, just can't access it. Query in the browser is returning:
{
"data": [
{
"name": "John Doe 1 ",
"id": "123456789"
},
{
"name": "John Doe 1 ",
"id": "123456789"
},
{
"name": "John Doe 1 ",
"id": "123456789"
}
]
}
Any help will be appreciated!
TIA!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个键值对,可以尝试 item.Value!
It's a key value pair sto try item.Value!