Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing an Array of Json into a C# Class
    text
    copied!<p>Here is my code:</p> <pre><code>Encoding enc = System.Text.Encoding.GetEncoding(1252); StreamReader loResponseStream = new StreamReader(resp.GetResponseStream(), enc); JsonSerializer serializer = new JsonSerializer(); JsonTextReader jsreader = new JsonTextReader(loResponseStream); results = (mHealthData)serializer.Deserialize(jsreader, typeof(mHealthData)); *** loResponseStream.Close(); public class mHealthData { // Class for the Mhealth Data public class RootObject { public string source { get; set; } public string name { get; set; } public string type { get; set; } public string unit { get; set; } public double value { get; set; } public string timestamp { get; set; } } } </code></pre> <p>This is the error I receive On the line marked with a <strong><em>*</em>*</strong>:</p> <blockquote> <p>Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'MHealthPlugin.mHealthData' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like <code>List&lt;T&gt;</code> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.</p> </blockquote> <p>I have no clue how to fix this. I've tried putting <code>List&lt;mHealthData&gt;</code> practically everywhere in the code and it doesn't help. The other rest Calls I do work fine. For reference, here is an example of what the JSON I'm trying to parse looks like:</p> <pre><code>[{"source":"hi","name":"G","type":"number","unit":null,"value":126,"timestamp":"1974-07-27T09:35:12Z"},{"source":"hi","name":"G","type":"number","unit":null,"value":120,"timestamp":"1974-07-27T09:35:12Z"}] </code></pre>
 

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