c# - Json into JArray -
i contence of json jarray.
my json response.content , returns follows:
{"type":"error","status":409,"code":"item_name_in_use","context_info":{"conflicts":[{"type":"file","id":"8195783794","sequence_id":"0","etag":"0","sha1":"2c483e55f677e1b45e21efda3e2d144a800f61f4","name":"df750784-1302-4dcb-8489-4d6847e91bb6.jpg"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"item same name exists","request_id":"475604999519b344223055"}
here is in neat view:
{"type":"error","status":409, "code":"item_name_in_use", "context_info":{"conflicts":[{"type":"file", "id":"8195783794", "sequence_id":"0", "etag":"0", "sha1":"2c483e55f677e1b45e21efda3e2d144a800f61f4", "name":"df750784-1302-4dcb-8489-4d6847e91bb6.jpg"}]}, "help_url":"http:\/\/developers.box.com\/docs\/#errors", "message":"item same name exists", "request_id":"475604999519b344223055"}
how have tried far:
jobject jsonobject = jobject.parse(response.content); jarray repsoncearray = (jarray)jsonobject["entries"];
the above repsoncearray set null here ???
var entries = repsoncearray[0]; string code = (string)entries["code"];
below how intend use info upload images box: have used code upload files before that's in else section below. json above file conflict.
if (code == "item_name_in_use")//conflicted file { //update conflicted file var contextinfo = entries["context_info"]; jarray conflicts = (jarray)contextinfo["conflicts"]; var conflictedfile = conflicts[0]; string id = (string)conflictedfile["id"]; string etag = (string)conflictedfile["etag"]; boxinfodict = updateboxfile(id, etag, path); } else //no file in box, insert file { string fileid = (string)entries["id"]; //id of file on box string etag = (string)entries["etag"]; //etag of file on box //clear dictionary boxinfodict.clear(); //add files dictionary boxinfodict.add("id", fileid); boxinfodict.add("etag", etag); }
edit
a successfull file upload json returned is:
{"total_count":1,"entries":[{"type":"file","id":"8216257636","sequence_id":"0","etag":"0","sha1":"2c483e55f677e1b45e21efda3e2d144a800f61f4","name":"df750784-1302-4dcb-8489-4d6847e91bb6.jpg","description":"","size":156233,"path_collection":{"total_count":2,"entries":[{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"all files"},{"type":"folder","id":"471676976","sequence_id":"0","etag":"0","name":"formvalue"}]},"created_at":"2013-05-21t03:35:39-07:00","modified_at":"2013-05-21t03:35:39-07:00","trashed_at":null,"purged_at":null,"content_created_at":"2013-05-21t03:35:39-07:00","content_modified_at":"2013-05-21t03:35:39-07:00","created_by":{"type":"user","id":"186619823","name":"johan cloete","login":"johandk@pros.co.za"},"modified_by":{"type":"user","id":"186619823","name":"johan cloete","login":"johandk@pros.co.za"},"owned_by":{"type":"user","id":"186619823","name":"johan cloete","login":"johandk@pros.co.za"},"shared_link":null,"parent":{"type":"folder","id":"471676976","sequence_id":"0","etag":"0","name":"formvalue"},"item_status":"active"}]}
to understanding should use:
jarray repsonceerrorarray = (jarray)jsonobject["conflicts"];
but return's null.
Comments
Post a Comment