2

First, this has been asked a number of times but having read all the posts I found none provided an answer that fixed my particular scenario.

Also, please forgive any incorrect terminology as I may be misusing terms...

I am trying to take the JSON from this query and simply output to a textblock:

http://www.imdb.com/xml/find?json=1&nr=1&nm=on&q=jeniffer+garner

Which produces this:

 {
  "name_approx":[
    {
      "id":"nm0004950",
      "title":"",
      "name":"Jennifer Garner",
      "description":"Actress, Dallas Buyers Club"
    },
//more code
{
  "id":"nm3144518",
  "title":"",
  "name":"Jennifer Varner",
  "description":"Self, THS Investigates: Hot for Student"
}]}

The code I'm trying to use for this as follows.

Classes:

public class Movie
{
    public List<Stream> name_approx { get; set; }

    public Movie ()
    {}
}

public class Stream 
{
    public string id { get; set; }
    public string title { get; set; }
    public string name { get; set; }
    public string description { get; set; }

    public Stream ()
    {}
}

and...

searchOutput.Text = "";
searchStatusOutput.Text = "Awaiting Response...";
string userURI = inputAddress.Text;

var response = await httpClient.GetAsync(userURI);
response.EnsureSuccessStatusCode();

var content = await response.Content.ReadAsStringAsync();

Movie output = JsonConvert.DeserializeObject<Movie>(content);

//searchOutput.Text = ??????           

When I run this I can see that Movie Output correctly contains one 'name_approx' object and nested within it 20 'Streams' as I expect.

I cannot however figure out how to output this to my text block. I've tried numerous approaches and think I need to use some form of foreach however I'm stuck and cannot work it out.

1 Answer 1

1

Now that you have it as a Json object, you could serialize the parent object back to a formatted Json string and display it in <pre> tags to keep the formatting.

Json.Net has a method for this:

string json = JsonConvert.SerializeObject(movieObject, Formatting.Indented);
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much, I've been trying for 3 hours to do this myself before I posted here.
No worries mate, if your going to be using this library check out the documentation as its a very powerful.

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.