Deserializing JSON data to C# using JSON.NET

前端 未结 7 1726
离开以前
离开以前 2020-11-22 04:01

I\'m relatively new to working with C# and JSON data and am seeking guidance. I\'m using C# 3.0, with .NET3.5SP1, and JSON.NET 3.5r6.

I have a defined C# class that

7条回答
  •  失恋的感觉
    2020-11-22 04:52

    Have you tried using the generic DeserializeObject method?

    JsonConvert.DeserializeObject(myjsondata);
    

    Any missing fields in the JSON data should simply be left NULL.

    UPDATE:

    If the JSON string is an array, try this:

    var jarray = JsonConvert.DeserializeObject>(myjsondata);
    

    jarray should then be a List.

    ANOTHER UPDATE:

    The exception you're getting isn't consistent with an array of objects- I think the serializer is having problems with your Dictionary-typed accountstatusmodifiedby property.

    Try excluding the accountstatusmodifiedby property from the serialization and see if that helps. If it does, you may need to represent that property differently.

    Documentation: Serializing and Deserializing JSON with Json.NET

提交回复
热议问题