c# - How to parse JSON to Object which has a property -
i need data server "data" property, , jsonconvert.serializeobject()
return without. how can convert it?
from:
{ "name": "tiger nixon", "position": "system architect", "salary": "$320,800", "start_date": "2011/04/25", "office": "edinburgh", "extn": "5421" }
to:
{ "data": [{ "name": "tiger nixon", "position": "system architect", "salary": "$320,800", "start_date": "2011/04/25", "office": "edinburgh", "extn": "5421" }] }
in vb.net (can in c# , convert).
if you're starting instance of model class, can wrap in anonymous object , serialize that:
dim anon = new {.data = new list(of model) {model}} dim json string = jsonconvert.serializeobject(anon, formatting.indented)
fiddle: https://dotnetfiddle.net/45rtrc
if you're starting json string, can transform using jobject
:
dim jo jobject = jobject.parse(json) jo = new jobject(new jproperty("data", new jarray(jo))) json = jo.tostring()
fiddle: https://dotnetfiddle.net/ezp6qr
Comments
Post a Comment