0

我想将 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"];

以下是我打算如何使用信息将图像上传到框:我以前使用此代码上传文件,但在下面的 else 部分中。上面的 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"];

但这也返回一个空值。

4

0 回答 0