c# - Convert an object with array to only an array -
so have problem after deserialization json converts object (there no other way this). in object there object called "content".
this objects holds array since needs converted object comes out this:
object content = {[ { "geofence_id": 44896, "name": "waaaaaaaaaaaaa" }, { "geofence_id": 44920, "name": "work" } ]} (for no other way).
now wish know how convert object object array.
i tried:
geofenceresponse[] arr = content geofenceresponse[]; where content.content object shown in top snippet , geofenceresponse[] objectarray.
but resulted in arr being null.
a geofenceresponse looks this:
class geofenceresponse : response { public int geofence_id { get; set; } public string name { get; set; } } a response just:
class response { } since have multiple different ones.
but multiple of them in contect object.
your json seems invalid {[...]} not valid per http://www.json.org/ btw valid object wrapping of array {"content":[...]}
you should not wrap array object deserialize array directly:
string json = @"[ { 'name': 'product 1', 'expirydate': '2000-12-29t00:00z', 'price': 99.95, 'sizes': null }, { 'name': 'product 2', 'expirydate': '2009-07-31t00:00z', 'price': 12.50, 'sizes': null } ]"; list<product> products = jsonconvert.deserializeobject<list<product>>(json); sample taken https://www.newtonsoft.com/json/help/html/serializingcollections.htm
Comments
Post a Comment