0

我试图获取 id 字段

dynamic post = fb.Get("/" + radListControl2.SelectedItem + "/feed?fields=message");

int count = (int)post.data.Count;

for (int i = 0; i < count; i++)
{
    radListControl1.Items.Add(Convert.ToString(post.data[i].id));
}

它工作并返回:

{
  "data": [
    {
      "id": "5xxx269_10151xxx50270", 
      "created_time": "2013-05-24T12:52:24+0000"
    }, 
    {
      "id": "5xxx69_101515xxxx270", 
      "created_time": "2013-05-21T19:57:57+0000"
    }, 
    {
      "message": "xxxxx", 
      "id": "xxx_1015157xxx270", 
      "created_time": "2013-05-21T19:44:07+0000"
    }, 
    {
      "id": "xxx", 
      "created_time": "2013-05-21T19:28:32+0000"
    }, 
    {
      "id": "5xx69_1015xxx75270", 
      "created_time": "2013-05-19T22:02:24+0000"
    }, 
    {
      "id": "52xxx269_1xxxx40270", 
      "created_time": "2013-05-18T09:31:42+0000"
    }, 
    {
      "message": "xxxx", 
      "id": "xxxx", 
      "created_time": "2013-05-17T22:59:49+0000"
    }, 

在 radlistbox 中插入了 id xxx,但此代码返回相同的列表

int count = (int)post.data.Count;

for (int i = 0; i < count; i++)
{
    radListControl1.Items.Add(Convert.ToString(post.data[i].message));
}

但是 radlistbox 是空的,我只需要字段 Message 你能帮帮我吗?

4

2 回答 2

1

也许只有在有价值时才添加......

for (int i = 0; i < count; i++)
{
    string message = post.data[i].message;

    if (string.IsNullOrEmpty(message)) 
        continue;

    radListControl1.Items.Add(Convert.ToString(message));
}
于 2013-05-24T14:02:27.733 回答
0

您可以使用hasOwnProperty来检查对象上是否存在属性

if (post.data[i].hasOwnProperty("message") {
    radListControl1.Items.Add(Convert.ToString(post.data[i].message));
}
于 2013-05-24T14:03:32.460 回答