0

Hello I have here a json. In my code below it is html. My Problem is that I become this error : An Exception error of type "System.NullReferenceException" has occurred. I have also debug the code "html" have the json data but in the next to lines the Content are null.

"{\"data\":[{\"q_id\":\"1\",\"q_text\":\"Ich read technical.\"},{\"q_id\":\"2\",\"q_text\":\"I have a good appetit.\"},{\"q_id\":\"3\",\"q_text\":\"I wake up early in the morning.\"}

That is my code

var g = new System.Web.Script.Serialization.JavaScriptSerializer().DeserializeObject(html) as Dictionary<string, object>;
var h = g["data"] as Dictionary<string, object>;
lbfield.Content = h["q_text"].ToString();
MethodMan
  • 17,665
  • 6
  • 32
  • 52
myplanet
  • 15
  • 5
  • this json does not appear to be valid there are plenty of online Json Validator and formatters online [JSON Formmater & Validator](https://jsonformatter.curiousconcept.com/) – MethodMan Jan 03 '17 at 18:47
  • Yes the debugger show this so but it is json. I have an ident code of another json that looks the same but works. Therfore I do not know what I done wrong. – myplanet Jan 03 '17 at 18:49
  • The text you have shown appears to start out as JSON but is truncated. Also, `g["data"]` is an array, not a record, so `h["q_text"]` is not going to work. Please use a JSON parser like [JSON.NET](http://www.newtonsoft.com/json). – Dour High Arch Jan 03 '17 at 22:50

0 Answers0