c# - Linq JObject query -
i have problems jobject , jarray linq query. error:
unable cast object of type 'newtonsoft.json.linq.jobject' type 'newtonsoft.json.linq.jarray'.
my code:
string fetchresult = jsonconvert.serializeobject(sidebar, formatting.indented); jobject rss = jobject.parse(fetchresult); var jsonmodel = item in (jarray)rss["registrationcase"] select new datalist { registrationtypename = item["registrationtypename"].value<string>(), };
if remove (jarray) get: cannot access child value on newtonsoft.json.linq.jproperty.
json, jobject: e.g: want registrationtypename, firstname , value of journalnumber.
{ "status": null, "registrationcase": { "registrationtypename": " ", "expiredate": null, "personid": 7, "person": { "firstname": " ", "gendervalue": 2, "gender": 2, }, "userid": 7, "user": { "username": "no-dom\\wme", "lastname": null, "id": 7, }, "transactions": [], "comments": [], "customdata": [ { "key": "journalnumber", "value": "0654-84148-00000-25", "id": 3, }, { "key": "isconsentgiven", "value": "false", "id": 4, }, { ], "fileid": null, "file": null, "id": 7, } }
u can these values directly :
var registrationtypename = rss["registrationcase"]["registrationtypename"]; var firstname = rss["registrationcase"]["person"]["firstname"]; var journalnumber = rss["registrationcase"]["customdata"][0]["value"];
Comments
Post a Comment