1
解析json時出現問題,我希望有人能幫忙。在C#中解析JSON問題
這裏是一個JSON響應我從servcie得到
{
"name":"UPDATE_QUEUE",
"args":[
{
"message":[
{
"service_id":1,
"entered":"01:00",
"polaziste":"Tibljaska cesta 11, Rijeka",
"phone_number":"0992173439",
"destinacija":"Zabica 1, Rijeka",
"order":1,
"passanger_count":1,
"order_arival":"01:00"
},
{
"service_id":2,
"entered":"01:00",
"polaziste":"Cavle 15, Cavle",
"phone_number":"080",
"destinacija":"Centar 1, Matulji",
"order":1,
"passanger_count":3,
"order_arival":"01:00"
}
]
}
]
}
而且這裏是我的JSON對象類
class DispatchQueueItem
{
public RootObject RootObject { get; set; }
}
public class Message
{
public int service_id { get; set; }
public string entered { get; set; }
public string polaziste { get; set; }
public string phone_number { get; set; }
public string destinacija { get; set; }
public int order { get; set; }
public int passanger_count { get; set; }
public string order_arival { get; set; }
}
public class Arg
{
public List<Message> message { get; set; }
}
public class RootObject
{
public string name { get; set; }
public List<Arg> args { get; set; }
}
這是我的電話
API.jsonObjects.DispatchQueueItem items
= JsonConvert.DeserializeObject<API.jsonObjects.DispatchQueueItem>(data.MessageText);
我使用Newtonsoft JSON for c#.NET
當我嘗試致電items.RootObject.name
時,我什麼都沒有收到,甚至沒有觸發事件(例如messageBox.Show(items.RootObject.name)
)。
什麼是API.jsonObjects.DispatchQueueItem?你爲什麼不反序列化到正確的類型'JsonConvert.DeserializeObject(....)' –