c# - How to tell JSON.NET to deserialize JArray to a List<object> when object type is provided? -


let's have following class:

class foo {     public object any; } 

this class accepts in field any.

when call:

jsonconvert.deserializeobject<foo>("{any: 5}") 

any contains system.int64.

however, when call:

jsonconvert.deserializeobject<foo>("{any: [5]}") 

any contains newtonsoft.json.linq.jarray.

how configure json.net in case any contain list<object>?

clarification:

there anything, can call:

jsonconvert.deserializeobject<foo>("{any: 'c'}") 

or

jsonconvert.deserializeobject<foo>("{any: ['c', 5]}") 

more clarification:

i tell somehow json.net (maybe using jsonserializersettings):

when encounter object , json contains array, deserialize (for instance) list<object>.

your answer here

your [5] array. have cast list.


you create own converter, described here


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -