0

我正在使用 Json.Net 库。而且我无法将 JSON 对象返回到我的 c# 对象中。

我目前有:JSON

[{"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); 
        }

但是我需要为反向过程做什么?谁能帮我?

谢谢马蒂

4

2 回答 2

3
 var result = JsonConvert.DeserializeObject<List<OrderObject>>(inputJson);
于 2012-11-12T14:51:18.457 回答
1

尝试 SerializeObject 的倒数方法,即 DeserializeObject:

List<OrderObject> list = JsonConvert.DeserializeObject<List<OrderObject>>(inputJson);
于 2012-11-12T14:57:29.593 回答