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对象(例如{‘名’ :“value”}) into type 'System.Collections.Generic.List`1 [facebook.Program + RootObject]' 因为该类型需要一个JSON数组(例如[1,2,3])来正确地反序列化 。要解决这个错误,可以将JSON更改为JSON数组(例如[1,2,3]),或者更改反序列化类型,使其成为正常的 .NET类型(例如,不是像integer这样的基本类型,也不是集合 类型像一个数组或列表)可以是无法反序列化当前JSON对象(例如{“名称”:“值”})成型“System.Collections.Generic.List`1
我看了其他职位。
我的JSON是这样的:
{"data":[{"target_id":9503123,"target_type":"user"}]}
有*一个*根对象('{“data”:..}'),而不是它们的列表。 – user2864740