using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Facebook;
using Newtonsoft.Json;

namespace facebook
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new FacebookClient(acc_ess);
            dynamic result = client.Get("fql", new { q = "select target_id,target_type from connection where source_id = me()"});
            string jsonstring = JsonConvert.SerializeObject(result);

            //jsonstring {"data":[{"target_id":9503123,"target_type":"user"}]}
            List<RootObject> datalist = JsonConvert.DeserializeObject<List<RootObject>>(jsonstring);
        }

        public class Datum
        {
            public Int64 target_id { get; set; }
            public string target_type { get; set; }
        }

        public class RootObject
        {
            public List<Datum> data { get; set; }
        }
    }
}



我看了其他帖子。

我的json看起来像这样:
{"data":[{"target_id":9503123,"target_type":"user"}]}

最佳答案

为了清楚起见,除了@SLaks的答案之外,这意味着您需要更改此行:

List<RootObject> datalist = JsonConvert.DeserializeObject<List<RootObject>>(jsonstring);

像这样:
RootObject datalist = JsonConvert.DeserializeObject<RootObject>(jsonstring);

10-08 13:02