2

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.

2 Answers 2

2

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:

[{"AccountID":"demo","UserID":"1","Password":"*blank*","Active":"1","Name":""}]
[{"AccountID":"demo","UserID":"1","Password":"*blank*","Active":"1","Name":""}]

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.

Sign up to request clarification or add additional context in comments.

Comments

0

That's because your json string is in incorrect format
If you're going to use brackets [ then json has only one for arrays.Since your declaration is likely an array.Put your string(as I edited) into this site and see the result yourself.

[{"AccountID":"demo","UserID":"1","Password":"*blank*","Active":"1","Name":""},{"AccountID":"demo","UserID":"1","Password":"*blank*","Active":"1","Name":""}]

Comments

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.