1
我需要反序列化下面的Json,根據Jsonlint.com是有效的,但是我之前沒有遇到過,或者找不到類似Json的例子以及如何處理它?Json沒有名稱字段的反序列化
[1,"Bellegrove/Sherwood ","76705","486","Bexleyheath Ctr",1354565507000]
我現在的系統是這樣的:
數據類:
[DataContract]
public class TFLCollection
{ [DataMember(Name = "arrivals")]
public IEnumerable<TFLB> TFLB { get; set; }
}
[DataContract]
public class TFLB
{
[DataMember]
public string routeName { get; set; }
[DataMember]
public string destination { get; set; }
[DataMember]
public string estimatedWait { get; set; }
}
解串器:
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TFLCollection));
using (var stream = new MemoryStream(Encoding.Unicode.GetBytes(result)))
{ var buses = (TFLCollection)serializer.ReadObject(stream);
foreach (var bus in buses.TFLBuses)
{
StopFeed _item = new StopFeed();
_item.Route = bus.routeName;
_item.Direction = bus.destination;
_item.Time = bus.estimatedWait;
listBox1.Items.Add(_item);
我exsiting解串器通過其與完整JSON流和迭代工作,但在我新的Json中,我需要反序列化,它只有1個項目,所以我不需要迭代它。
那麼是否有可能使用類似的方法反序列化我的Json示例?
不用說,我會說特定的JSON字符串會反序列化爲'IEnumerable
它是有效的JSON - 它是一個字符串和數字的數組。 –