8

My JSON string looks like this. Please note that it has escape characters.

string json = "\"{\\\"Status\\\":true,\\\"ID\\\":24501}\"";

When I use the Parse method like below I run into an error stated below:

JObject o = JObject.Parse(json);

Error reading JObject from JsonReader. Current JsonReader item is not an object: String

How do I get rid of this error or is there any other method to parse my json string and fetch the values?

1
  • no answer of this, m facing the same prob Commented Jul 2, 2012 at 13:00

6 Answers 6

4

Remove first and last quotes:

string json = "{\"Status\":true,\"ID\":24501}";

See the Json format here.

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

Comments

2

It seems like your object is double encoded. Try:

string json = "{\"Status\":true,\"ID\":24501}";

2 Comments

That json string is what I get from an API. How do I remove the escape characters?\
@SVI : I'm late to the party but if anybody needs it, just replace them using something like json.Replace("\\\\", "\\")
1

You need something like this

json = json.Replace(@"\", string.Empty).Trim(new char[]{'\"'})

Comments

0

in here format should be something like this:

string jsonNew = @"{'Status': True,'ID': 24501 }";

Comments

0

As SolarBear says in his comment, the problem is double-escaping.

To get the proper format, like this:

string json = "{\"Status\":true,\"ID\":24501}";

Do something like this:

json = json.Replace("\\\\", "\\");

Comments

0

Had similar issue today. My solution to this is contained in this extension method (using c#):

public static class StringExtensions
{
    public static string RemoveDoubleEncoding(this string text)
    {
        if(string.IsNullOrEmpty(text))
            return string.Empty;
        var result = text.TrimStart('\"').TrimEnd('\"');
        result = result.Replace(@"\", string.Empty);
        return result;
    }
}

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.