Json进入JArray

时间:2013-05-21 10:06:27

标签: c# arrays json box-api

我想让json成为JArray。

我的json是response.Content并返回如下:

{"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 with the same name already exists","request_id":"475604999519b344223055"}

这是一个整洁的观点:

     {"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 with the same name already exists",
     "request_id":"475604999519b344223055"}

到目前为止我是如何尝试的:

 JObject jsonObject = JObject.Parse(response.Content);
 JArray repsonceArray = (JArray)jsonObject["entries"]; 

上面的repsonceArray在这里设置为null ???

var entries = repsonceArray[0];
string code = (string)entries["code"];

以下是我打算如何使用信息将图片上传到框中: 我之前使用此代码上传文件,但是在下面的其他部分中。 上面的json用于文件冲突。

if (code == "item_name_in_use")//Conflicted file
   {
     //Update the 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 the file
   {
     string fileId = (string)entries["id"]; //Id of file on Box
     string etag = (string)entries["etag"]; //etag of the file on box

     //Clear dictionary
     boxInfodict.Clear();

     //Add files to a dictionary
     boxInfodict.Add("id", fileId);
     boxInfodict.Add("etag", etag);
   }

修改


Json返回的成功文件上传是:

{"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"}]}

根据我的理解,我应该使用:

JArray repsonceErrorArray = (JArray)jsonObject["conflicts"];

但这也是一个空的。

0 个答案:

没有答案