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

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.