我正在使用 Json.Net Libary。 而且我在将 JSON 对象重新放入我的 C# 对象时遇到问题。
我目前有:杰伦
[{"Datum":"31-05-2012","Naam":"KN: xxxx","Prijs":"37","Id":31123,"status":"found","foundPrice":"37.50","betaald":"2012-06-01","ingepakt":"2012-06-03","geanuleerd":"nee","verstuurd":"nee","achternaam":"xxxx","straat":"xxxx 98","postcode":"4422xx","plaats":"xxxxx","land":"Nederland","gewicht":"0.600"},{"Datum":"31-05-2012","Naam":"xxxxT","Prijs":"23","Id":31341,"status":"found","foundPrice":"23.00","betaald":"2012-06-01","ingepakt":"2012-06-03","geanuleerd":"nee","verstuurd":"nee","achternaam":"xxxx","straat":"de xxxxx 2","postcode":"4444xx","plaats":"xxxx","land":"Nederland","gewicht":"0.300"}]
和对象:
public class OrderObject
{
public string Datum, Naam, Prijs;
public int Id;
public string status;
public string foundPrice;
public string betaald;
public string ingepakt;
public string geanuleerd;
public string verstuurd;
public string achternaam;
public string straat;
public string postcode;
public string plaats;
public string land;
public string gewicht;
}
要将这些对象列表到 JSON,我只需要:
private void sentToServer(List<OrderObject> input )
{
var inputJson = JsonConvert.SerializeObject(input);
}
但是我需要为反向过程做什么?谁能帮我?
感谢马西
var result = JsonConvert.DeserializeObject<List<OrderObject>>(inputJson);
尝试倒
数方法来序列化对象,即反序列化对象:
List<OrderObject> list = JsonConvert.DeserializeObject<List<OrderObject>>(inputJson);