Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating an array from JSON
    primarykey
    data
    text
    <p>I am trying to parse into an application a JSON string that is multidimensional. Here's a snipping of the string:</p> <p>{"one": {"Title": "There Goes the Musical Neighborhood", "Body": "On April 18th Public Enemy..."},"two": {"Title": "Public Enemys DJ Lord Tours Australia", "Body": "Public Enemys...</p> <p>So as you can hopefully see I have a key ("one") with a value set to a second JSON string with keys starting at "title" and "body" each with their own string values.</p> <p>My webservice that i use to output the string works fine parsing in a SINGLE key-value pair (EX. {"Title": "There Goes the Musical Neighborhood", "Body": "On April 18th Public Enemy..."} will parse and store the strings into my created class since I am using Json.Net and able to simple pair the keys with the class members.</p> <p>Now I need to parse up to (but not necessarily all) five strings into my application to output to the user.</p> <p>I first tried to Parse each value from the first array (EX. {"one": {"Title": ...) so that the string it stores would be a single JSON string that I can parse into its own object, but it seems to be returning an error with an unexpected token of "one" when I run my code.</p> <p>Here is how I am parsing this.</p> <pre><code> var request = HttpWebRequest.Create(string.Format(@"http://moon.eastlink.com/~jandrews/webservice2.php")); request.ContentType = "application/json"; request.Method = "GET"; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { var content = reader.ReadToEnd(); if(string.IsNullOrWhiteSpace(content)) { Console.Out.WriteLine("Response contained empty body..."); } else { Console.Out.WriteLine("Response Body: \r\n {0}", content); NewsArray news = JsonConvert.DeserializeObject&lt;NewsArray&gt;(content); </code></pre> <p>My response before deserializing the object is the entire string fine and outputs to the console in one piece, so I know the stream reader is grabbing the string. However once it tries to deserialize the object I get an error "Invalid token at line 1 position 9". It may have to do with how I am escaping the string brackets but it worked fine in the online parser. The site is where my full string is so you can take a look. Any idea what's wrong or if there is a better way of going about this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload