Parsing Json rest api response in C# -
this question has answer here:
- how can parse json c#? 10 answers
i trying pull value rest api json response using c#
i have follow code
client.baseurl = "https://api.cloud.appcelerator.com"; request.resource = "/v1/chats/create.json?key=" + cac.appcode.tostring(); request.method = method.post; request.addurlsegment("appkey", "key"); var response = client.execute(request);
in "response" json content follow:
{ "meta": { "code": 200, "status": "ok", "method_name": "createchatmessage" }, "response": { "chats": [ { "id": "521cfcd840926a0b3500449e", "created_at": "2013-08-27t19:24:08+0000", "updated_at": "2013-08-27t19:24:08+0000", "message": " join chat group, welcome …", "from": { "id": "520f41e125e74b0b2400130a", "first_name": "administrator", "created_at": "2013-08-17t09:26:57+0000", "updated_at": "2013-08-27t19:23:10+0000", "external_accounts": [ ], "email": "roy@tomax.co.il", "confirmed_at": "2013-08-17t09:26:57+0000", "username": "admin", "admin": "true", "stats": { "photos": { "total_count": 0 }, "storage": { "used": 0 } } }, "chat_group": { "id": "521cfcd840926a0b3500449d", "created_at": "2013-08-27t19:24:08+0000", "updated_at": "2013-08-27t19:24:08+0000", "message": " join chat group, welcome …", "participate_users": [ { "id": "520f41e125e74b0b2400130a", "first_name": "administrator", "created_at": "2013-08-17t09:26:57+0000", "updated_at": "2013-08-27t19:23:10+0000", "external_accounts": [ ], "email": "roy@tomax.co.il", "confirmed_at": "2013-08-17t09:26:57+0000", "username": "admin", "admin": "true", "stats": { "photos": { "total_count": 0 }, "storage": { "used": 0 } } } ] } } ] } }
how pull follow value "id": "521cfcd840926a0b3500449e" ? using c#....
1> add namspace. using newtonsoft.json.linq;
2> use source code.
jobject joresponse = jobject.parse(response); jobject ojobject = (jobject)joresponse["response"]; jarray array= (jarray)ojobject ["chats"]; int id = convert.toint32(array[0].tostring());
Comments
Post a Comment