{
[DataMember(Name = “Success”)]
public string Success { get; set; }
[DataMember(Name = “Msg”)]
public string Msg { get; set; }
[DataMember(Name = “OrderId”)]
public string OrderId { get; set; }
[DataMember(Name = “Name”)]
public string Name { get; set; }
[DataMember(Name = “Plate”)]
public string Plate { get; set; }
[DataMember(Name = “InTime”)]
public string InTime { get; set; }
[DataMember(Name = “OutTime”)]
public string OutTime { get; set; }
[DataMember(Name = “UserType”)]
public string UserType { get; set; }
[DataMember(Name = “ParkingSite”)]
public string ParkingSite { get; set; }
[DataMember(Name = “ParkingTime”)]
public string ParkingTime { get; set; }
[DataMember(Name = “ParkingFee”)]
public string ParkingFee { get; set; }
[DataMember(Name = “ParkingActFee”)]
public string ParkingActFee { get; set; }
private SortedDictionary<string, object> SiWovalues = new SortedDictionary<string, object>();
public void SiWoSetValue(string key, object value)
{
SiWovalues[key] = value;
}
public object SiWoGetValue(string key)
{
object o = null;
SiWovalues.TryGetValue(key, out o);
return o;
}
public SortedDictionary<string, object> SiWoFromXml(string serverUrl_g,string Data)
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<SiWoData>));
string response_g = Service.HttpGetConnectToServer(serverUrl_g, Data);
//string str = File.ReadAllText(“a.txt”); //假设上面的数据存在a.txt里,从其他地方来的也行,赋值给str就行
response_g = “[” + response_g + “]”;
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(response_g)))
{
List<SiWoData> datas = (List<SiWoData>)serializer.ReadObject(ms);
foreach (SiWoData data in datas)
{
// Console.WriteLine(data.From);
}
}
}
return SiWovalues;
}
}
20
2、在foreach里直接result.Add(data.***,data)就行啊
3、最好SortedDictionary<string, object>都改成SortedDictionary<string, SiWoData>
20
假如你的字符串是json或xml格式,那么可以直接反序列化为对象集合,假如是csv格式的话,也可以通过CSVHelper直接反序列化成集合,假如还有其它格式,那就要本人写代码解析了