我有這樣的JSON字符串Windows Phone 7的JSON解析錯誤
{ "rs:data": { "z:row": [ {"Lead": "", "Industry": "Other Commercial", "ID": "908", "Name": "3PAR Ltd." }, {"Lead": "Ebeling, Kevin R.", "Industry": "Retail", "ID": "1", "Name": "7-Eleven" } ] }}
現在我在上面的格式從Web服務將數據傳輸到贏手機7. 但是當試圖解析我面臨的一個錯誤:
void fetcher_GetClientsCompleted(object sender, ServiceReference2.GetClientsCompletedEventArgs e)
{
StringReader reader;
reader = new StringReader(e.Result);
IList<Clientclass> cc;
string MyJsonString = reader.ReadToEnd(); //
cc = Deserialize(MyJsonString);
}
public static IList<Clientclass> Deserialize(string json)
{
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(json)))
{
var serializer = new DataContractJsonSerializer(typeof(IList<Clientclass>));
return (IList<Clientclass>)serializer.ReadObject(ms);
}
}
我的數據必須解析爲每clientclass,其中clientclass是:
public class Clientclass
{
string _id;
string _name;
string _industry;
string _lead;
public string ID
{
get { return _id; }
set { _id = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Industry
{
get {return _industry; }
set { _industry= value; }
}
public string Lead
{
get { return _lead; }
set { _lead = value; }
}
}
請注意JSON字符串中有多個記錄。
感謝 santu
和錯誤是...? – 2011-05-11 12:33:53