0
public class JSON_Browse_Root
{
    public string browse_content { get; set; }
    public List<JSON_Browse_Content> Content { get; set; }
}

public class JSON_Browse_Content
{
    public string link { get; set; }
    public string image { get; set; }
    public string title { get; set; }
    public string description { get; set; }
    public string rating { get; set; }
    public string genre { get; set; }
}

using (var client = new HttpClient())
{
    using (HttpResponseMessage response = await client.GetAsync("https://myjsonurl.com"))
    using (HttpContent responseData = response.Content)
    {
        var jsonData = await responseData.ReadAsStringAsync();
        var root = JsonConvert.DeserializeObject<JSON_Browse_Root>(jsonData);
    }

}

JSON:

{
    "browse_content": [
        {
            "link": "https:\/\/blah",
            "image": "https:\/\/blahblah.blah.gif",
            "title": "Mr. Southern Hospitality",
            "description": "He got old money",
            "rating": "e",
            "author": "",
            "genre": "Comedy - Original"
        },
        {
            "link": "https:\/\/blah",
            "image": "https:\/\/blahblah.blah.png",
            "title": "Throwverwatch",
            "description": "Based on the competitive overwatch experience",
            "rating": "t",
            "author": "",
            "genre": "Comedy - Parody"
        }

An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in System.Private.CoreLib.ni.dll but was not handled in user code Unexpected character encountered while parsing value: [

I used this JSON for iOS and Android apps and it's worked perfectly. Also, jsonlint.com says the JSON is valid. Not sure why it's erroring out on the [ character.

3
  • 1
    This has a ] } missing. What do you mean by jsonLint says it's okay? What have you tested there? Commented Feb 12, 2018 at 23:21
  • 2
    jsonlint.com tells me Parse error on line 18. Wonder how you got it to say it was valid Commented Feb 12, 2018 at 23:24
  • 1
    This is almost certainly just a copy/paste error when writing the question. The error message posted doesn't match the bad JSON data shown. My answer tells you why it's not working. Commented Feb 12, 2018 at 23:42

1 Answer 1

3

Assuming your JSON is missing the ending due to a copy/paste error, the actual problem you have is that your model class is wrong. You have a string property called browse_content and the deserialiser is trying to feed the array (i.e. the [...]) part of the JSON into it, hence you get the error about the unexpected character [. So the simple fix is to update your model to this:

public class JSON_Browse_Root
{
    public List<JSON_Browse_Content> browse_content { get; set; }
}
Sign up to request clarification or add additional context in comments.

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.