am trying to consume json strings inside asp.net and google told me about this Json.NET library.
I have the following json from a php webservice:
"[{\"AccountID\":\"demo\",\"UserID\":\"1\",\"Password\":\"*blank*\",\"Active\":\"1\",\"Name\":\"\"}][{\"AccountID\":\"demo\",\"UserID\":\"1\",\"Password\":\"*blank*\",\"Active\":\"1\",\"Name\":\"\"}]"
i found that the library cannot load urls so i had to use System.Net.WebClient; ok so far.
The problem is that doing
var json = webClient.DownloadString(url); //gives the json above
object user = JsonConvert.DeserializeObject(json);
// or User user =JsonConvert.DeserializeObject<User>(json); wont work
wont work the library says “After parsing a value an unexpected character was encountered”
So, is my json malformed? i construct it with json_encode($resultset) from php, so i wonder whats going on.
my User object only has the properties i have on json.
First of all, your JSON string has double quotes around the whole result and a backslash before every other double quote. I’ll assume that this is an artifact from copying it out of the VisualStudio debugger (which displays it like this).
If we remove these backslashes, we get the following JSON:
These are two identical JSON arrays. But a valid JSON response consists of either a single JSON object or a single JSON array. This response is invalid.
It’s seems that two JSON response where concatenated, resulting in an invalid construct.