Error when deserializing JSON to Object

前端 未结 7 2099
别跟我提以往
别跟我提以往 2020-12-18 04:29

I need to convert JSON data that I get from a REST API and convert them to CSV for some analytic. The problem is that the JSON data do not necessarily follow the same conten

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 04:45

    As far as I can tell, more recent versions of Newtonsoft can actually do this now, no additional work required.

    I was working with the binary version however, and this did still have the issue - I had a test where you could configure to use binary or json, and the json version worked just fine, but the binary complained about not getting an array type.

    I started using the BsonDataReader for this, and was looking through the properties and methods on it to see how I could best look at the contents, and lo and behold, this had a property called:

    reader.ReadRootValueAsArray 
    

    Setting this to 'true' did the trick.

提交回复
热议问题