1

I am trying to display data collected from RestSharp. Just for example i have the following code but don't know how to display the data as it currently is.

 private void readJSON()
    {
        string url = "http://www.jsonurl.com";
        var restClient = new RestClient(url);
        var request = new RestRequest(Method.GET);
        //82.147.22.3
        //What we are requesting:value
        request.AddParameter("apikey", "xxxxxtheapikeygoesherexxxxx");

        restClient.ExecuteAsync<Entry>(request, response =>
        {
            //What to do with the JSON?
        });
    }

I know i need to place the JSON between the ExecuteAsync<>() but i want to be able to take the data and for example place it into a listbox. Below is an example of the result given back to me from JSONtoSharp.com. code:

    public class Change
    {
        public string direction { get; set; }
        public int amount { get; set; }
        public int actual { get; set; }
    }

    public class itementry
    {
        public int position { get; set; }
        public int prePosition { get; set; }
        public int Weeks { get; set; }
        public string ar { get; set; }
        public string ti { get; set; }
        public Change ch { get; set; }
    }

    public class RootObject
    {
        public int charDate { get; set; }
        public int retrieved { get; set; }
        public List<Entry> entries { get; set; }
    }

I am sure the answer is simple as glass and I just need help as i am completely lost in this one.. cant find any good documentation to help me out!

Note: This is for C# on Windows Phone 7 using RestSharp and Newtonsoft

Dean Meehan
  • 2,511
  • 22
  • 36
  • Possible duplicate - http://stackoverflow.com/questions/10153749/how-should-i-implement-executeasync-with-restsharp-on-windows-phone-7 – indyfromoz Sep 21 '12 at 01:48

1 Answers1

2
restClient.ExecuteAsync<Entry>(request, response =>
    {
        //Supply your JSON data to a callback
        Callback(response.Data);
    });

public void Callback(string jsonResponse)
{
    var responseList = JsonConvert.DeserializeObject<RootObject>(jsonResponse);
    //Assuming you have properly setup binding properties for Listbox, databind listbox here
    YourListBox.ItemsSource = responseList.entries;
}

Here JsonConvert is from NewtonSoft package

nkchandra
  • 5,585
  • 2
  • 30
  • 45
  • You shouldn't assume, how would I set up binding for the JSON input? I'm really new in this field and even the correct documentation would be great!! I have the field to be binded but how do I set them up to get the data from the JSON – Dean Meehan Sep 22 '12 at 00:44
  • 2
    I should assume..and I can only assume because you didnt share any of your Listbox xaml and your binding requirements. You are expecting us to write a complete program for you?? In your question you have asked how to parse JSON data. I have showed you. Please update your question with some additional data. – nkchandra Sep 22 '12 at 04:55