I created one web service application in windows phone 7. this is JSON array get from belowed uri. ...[{"id":4,"name":"Bangalore"},{"id":1,"name":"Chennai"},{"id":3,"name":"Hyderabad"},{"id":2,"name":"Mumbai"}]...
List item = (List)ds.ReadObject(msnew); In this line one bug(it says while run). There was an error deserializing the object of type.Data at the root level is invalid. Line 1, position 1.
coding:
public MainPage() { InitializeComponent(); }
[DataContract]
public class Item
{
[DataMember]
public int id
{
get;
set;
}
[DataMember]
public string name
{
get;
set;
}
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri("http://75.101.161.83:8080/CityGuide/Cities?authId=CITY4@$pir*$y$t*m$13GUID*5"));
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
}
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string MyJsonString = e.Result;
// MessageBox.Show(e.Result);
DataContractSerializer ds = new DataContractSerializer(typeof(Item));
MemoryStream msnew = new MemoryStream(Encoding.UTF8.GetBytes(MyJsonString));
List<Item> item = (List<Item>)ds.ReadObject(msnew);
}