• Resolved cm3solutions

    (@cm3solutions)


    I am trying to take the json on DeserializeObject it so I can use the player data in my application. My code looks like this.

    List<Root> list;
    
                string json = new WebClient().DownloadString(URL_Player);
       
                list = JsonConvert.DeserializeObject<List<Root>>(json);

    Root is a class I created and it works fine if I return a single player like this

    list = JsonConvert.DeserializeObject<Root>(json);

    Its just when I try to return a full list of players I get

    “Newtonsoft.Json.JsonSerializationException: ‘Cannot deserialize the current JSON object (e.g. {“name”:”value”}) into type ‘System.Collections.Generic.List`1[System.Object]’ because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
    To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.”

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Roch

    (@rochesterj)

    Hi there!

    Thanks for reaching out.

    I’m not sure if we can help you with this one though as it is related to custom coding.

    @savvasha, do you have any ideas about this one?

    Thanks!

    Plugin Contributor Savvas

    (@savvasha)

    Hmm, SportsPress uses the native wordpress framework for REST API. I am not sure that is wise to alterate the output format instead of adapt the way the client process the site’s json response.

    Thanks,
    Savvas

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘C# DeserializeObject’ is closed to new replies.