C# 如何将json转换为本地数据库类属性
我有一个将json值转换为本地数据库类的问题 如果我使用list代替EntitySet,它可以正常工作 这是我的类属性 当我从代码转换下面的类时C# 如何将json转换为本地数据库类属性,c#,linq,serialization,windows-phone-8,C#,Linq,Serialization,Windows Phone 8,我有一个将json值转换为本地数据库类的问题 如果我使用list代替EntitySet,它可以正常工作 这是我的类属性 当我从代码转换下面的类时 HttpClient client = new HttpClient(); var data = await client.GetStringAsync("http://demo.com/wk/lg/initimeiNumber=911115000013916&tz=Asia/Kolkata"); Info_Entity = JsonConve
HttpClient client = new HttpClient();
var data = await client.GetStringAsync("http://demo.com/wk/lg/initimeiNumber=911115000013916&tz=Asia/Kolkata");
Info_Entity = JsonConvert.DeserializeObject<Info>(data);
您没有传递用于反序列化的数组(如异常所述)。您传递的对象中包含数组,但不是实际数组。您需要传递json对象的taskarray属性
此外,您的Info类与您从服务器接收到的json不匹配。您能告诉我们变量数据是什么样子的吗?您能告诉我们json吗。@guiomie,我使用了json格式我已经避免了这一点,使用sqlite请看我的问题
[Table]
public class Detail
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int id { get; set; }
[Column]
public string MobileNo { get; set; }
private EntityRef<DetailInfo> _DetailInfo;
[Association(Storage = "_DetailInfo", ThisKey = "id", OtherKey = "Did", IsForeignKey = true)]
public DetailInfo DetailInfo
{
get { return _DetailInfo.Entity; }
set
{
_DetailInfo.Entity = value;
}
}
}
[Table]
public class DetailInfo
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int Did { get; set; }
[Column]
public string phoneno { get; set; }
[Column]
public string address { get; set; }
private EntityRef<Info> _info;
[Association(Storage = "_info", ThisKey = "Did", OtherKey = "Id", IsForeignKey = true)]
public Info Info
{
get { return _info.Entity; }
set { _info.Entity = value;}
}
private EntitySet<Detail> _Detail;
[Association(Storage = "_Detail", OtherKey = "id", ThisKey = "Did")]
public EntitySet<Detail> Detail
{
get { return this. _Detail; }
set { this._Detail.Assign(value); }
}
public DetailInfo()
{
_Detail = new EntitySet<Detail>(
new Action<Detail>(this.attach_ToDo),
new Action<Detail>(this.detach_ToDo)
);
}
private void attach_ToDo(Detail Dinfo)
{
Dinfo.DetailInfo = this;
}
// Called during a remove operation
private void detach_ToDo(Detail Dinfo)
{
Dinfo.DetailInfo = this;
}
}
[Table]
public class Info
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
public int Id { get; set; }
[Column]
public string firstName { get; set; }
[Column]
public string lastName { get; set; }
[Column]
public string imageUrl { get; set; }
private EntitySet<DetailInfo> _DetailInfo;
[Association(Storage = "_DetailInfo", OtherKey = "Did", ThisKey = "Id")]
public EntitySet<DetailInfo> DetailInfo
{
get { return this._DetailInfo; }
set { this._DetailInfo.Assign(value); }
}
public Info()
{
_DetailInfo = new EntitySet<DetailInfo>(
new Action<DetailInfo>(this.attach_ToDo),
new Action<DetailInfo>(this.detach_ToDo)
);
}
private void attach_ToDo(DetailInfo Dinfo)
{
Dinfo.Info = this;
}
private void detach_ToDo(DetailInfo Dinfo)
{
Dinfo.Info = null;
}
}
"result":{
"taskarray":[
{
"lon":79.0630932,
"status":1,
"expdate":1.39054962e12,
"date":"1390463355000",
"clientname":"pranit",
"id":1336,
"csoId":"we1141",
"title":"New Mobile",
"customercontact":"9595588794",
"address":"Dharampeth , Nagpur",
"priority":0,
"description":"none",
"comment":"none",
"note":"none",
"lat":21.1389989
},
{
"lon":79.0743915,
"status":1,
"expdate":1.39046334e12,
"date":"1390463446000",
"clientname":"bb",
"id":1337,
"csoId":"asdf",
"title":"xyz",
"customercontact":"9595588794",
"address":"Sadar, Nagpur",
"priority":2,
"description":"none",
"comment":"none",
"note":"none",
"lat":21.1632626
}
]
},
"status":"success",
"loccheckincom":"",
"code":"200"
}