How can I parse the following JSON for WP7 and bind to a listbox?

Up vote 0 down vote favorite share g+ share fb share tw.

I'm having some trouble binding this json to a ListBox...The problem seems to happen in the ActivityTrack class/object of the JSON...i'm not sure what is not meshing... {"collection":{"type":"track","created_at":"2011/09/18 14:04:00 +0000","origin":{"id":23606164,"created_at":"2011/09/18 14:03:59 +0000","user_id":222927,"duration":342465,"commentable":true,"state":"finished","sharing":"public","tag_list":"garage usgarage soulfulhouse house deephouse deep","permalink":"pablo-cortez-when-i-need-u","description":"","streamable":true,"downloadable":false,"genre":"UK Garage","release":"","purchase_url":null,"label_id":null,"label_name":"","isrc":"","video_url":null,"track_type":"demo","key_signature":"","bpm":null,"title":"Pablo Cortez - When I Need U (Back To 90s Mix)","release_year":null,"release_month":null,"release_day":null,"original_format":"mp3","license":"all-rights-reserved","uri":"https://api.soundcloud.com/tracks/23606164","permalink_url":"

","user":{"id":222927,"permalink":"pablocortez","username":"Pablo Cortez","uri":"https://api.soundcloud.com/users/222927","permalink_url":"
?ca13f03"},"stream_url":"https://api.soundcloud.com/tracks/23606164/stream","user_playback_count":1,"user_favorite":false,"playback_count":28,"download_count":0,"favoritings_count":0,"comment_count":2,"attachments_uri":"https://api.soundcloud.com/tracks/23606164/attachments","sharing_note":{"text":"My new sounds","created_at":"2011/09/18 14:03:59 +0000"}},"tags":"affiliated"},"next_href":"https://api.soundcloud.com/me/activities/track.json?cursor=86db5e5e-e1fe-11e0-9c69-0f0dad493cfc\\u0026limit=1","future_href":"https://api.soundcloud.com/tracks/236061640"} Here is the class structure which I am trying to bind the JSON too public class Activities { public ActivityTrack activities { get; set; } public string next_href { get; set; } public string future_href { get; set; } } public class ActivityTrack { public string type { get; set; } public string created_at { get; set; } public OriginActivityTrack origin { get; set; } public string tags { get; set; } } public class OriginActivityTrack { public string id { get; set; } public string created_at { get; set; } public string user_id { get; set; } public string duration { get; set; } public string commentable { get; set; } public string state { get; set; } public string sharing { get; set; } public string tag_list { get; set; } public string permalink { get; set; } public string description { get; set; } public string streamable { get; set; } public string downloadable { get; set; } public string genre { get; set; } public string release { get; set; } public string purchase_url { get; set; } public string label_id { get; set; } public string label_name { get; set; } public string isrc { get; set; } public string video_url { get; set; } public string track_type { get; set; } public string key_signature { get; set; } public string bpm { get; set; } public string title { get; set; } public string release_year { get; set; } public string release_month { get; set; } public string release_day { get; set; } public string original_format { get; set; } public string license { get; set; } public string uri { get; set; } public string permalink_url { get; set; } public string artwork_url { get; set; } public string waveform_url { get; set; } public SmallUser user { get; set; } public string stream_url { get; set; } public string user_playback_count { get; set; } public string user_favorite { get; set; } public string playback_count { get; set; } public string download_count { get; set; } public string favoritings_count { get; set; } public string comment_count { get; set; } public string attachments_uri { get; set; } public SharingNote sharing_note; } public class SharingNote { public string text { get; set; } public string created_at { get; set; } } public class SmallUser { public string id { get; set; } public string permalink { get; set; } public string username { get; set; } public string uri { get; set; } public string permalink_url { get; set; } public string avatar_url { get; set; } } This is the current code for binding to listbox: private void ReadCallbackDashboard(IAsyncResult asynchronousResult) { lock (locker) { try { HttpWebRequest request = (HttpWebRequest)asynchronousResult. AsyncState; HttpWebResponse response = (HttpWebResponse)request. EndGetResponse(asynchronousResult); using (StreamReader streamReader1 = new StreamReader(response.

GetResponseStream())) { string resultString = streamReader1.ReadToEnd(); using (var ms = new MemoryStream(Encoding.Unicode. GetBytes(resultString))) { if (ms! = null) { var ser = new DataContractJsonSerializer(typeof(Activities)); Activities obj = (Activities)ser.

ReadObject(ms); userDashboardActivities = null; userDashboardActivities = new ObservableCollection(); for (int I = 0; I mainMessage. Text = messageDashboard); } else { messageDashboard = ""; UIThread. Invoke(() => mainMessage.

Text = messageDashboard); UIThread. Invoke(() => dashboardBox. ItemsSource = userDashboardActivities); } } } } } catch (WebException we) { UIThread.

Invoke(() => MessageBox. Show("Could not retrieve the latest. Internet down?

Try a refresh. ")); } } } please check it out! Thanks in advance!

Json windows-phone-7 listbox soundcloud link|improve this question edited Sep 19 '11 at 6:30Claus Jørgensen10.4k41238 asked Sep 19 '11 at 2:32ice9111756.

2 You have called your property activities but the json calls it collection. Is there a missing mapping file you didn't include? Or is the problem as simple as this?

– Chris Sainty Sep 19 '11 at 5:40 1 What happens with your code? Is an exception thrown? Nothing happens?

Please give us some more information! – ColinE Sep 19 '11 at 7:28 @ColinE - Sorry, the code throws an exception when I try to access obj. Activities -- obj.activities.

Length and userDashboardActivities. Add(obj. Activitiesi); NullReferenceException because Activites never got filled with information from the json – ice911 Sep 19 '11 at 15:07 @Chris Sainty - You are the man!

Thanks for the second pair of eyes! – ice911 Sep 19 '11 at 15:20 @Chris Sainty - post an Answer so I can award this question to you as Answered. Thanks again!

– ice911 Sep 19 '11 at 15:36.

Answer as discovered in the comments. You have called your property activities but the json calls it collection.

Thanks again! Can't believe I missed that! Looked it over like 100 times before I posted the question.

– ice911 Sep 20 '11 at 17:16.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions