反应原生0.53.3的Json解析问题

时间:2018-06-08 06:56:24

标签: react-native

我在react-native api调用中得到了无效的json字符串,它在某些时候发生了无效的json并返回null。如果有人能解决这个问题,请告诉我。

/node_modules/react-native/Libraries/Network/XMLHttpRequest.js

case 'json':
        try {
          this._cachedResponse = JSON.parse(this._response);
        } catch (_) {
          this._cachedResponse = null;
        }
        break;

1 个答案:

答案 0 :(得分:0)

 {"data":[{"id":583,"type":"itemcomment","type_id":10036,"datetime":"2018-05-15T06:48:39","status":1,"user_id":8,"type_name":"test new","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"}},{"id":581,"type":"itemcomment","type_id":10036,"datetime":"2018-05-15T06:48:05","status":1,"user_id":8,"type_name":"test new","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"}},{"id":578,"type":"itemcomment","type_id":10036,"datetime":"2018-05-15T06:42:50","status":1,"user_id":8,"type_name":"test new","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"}},{"id":449,"type":"editoutfits","type_id":5,"datetime":"2018-05-09T10:48:15","status":1,"user_id":8,"type_name":"Test","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"oufitimg":"1525758248newlookImage.jpg"},{"id":430,"type":"edititem","type_id":10034,"datetime":"2018-05-08T07:59:29","status":1,"user_id":8,"type_name":"Item3","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"itemimg":[{"image":"1524568505IMG_0344.PNG"},{"image":"1525761327virtual_closet_mobile.jpg"}]},{"id":427,"type":"edititem","type_id":10034,"datetime":"2018-05-08T06:35:26","status":1,"user_id":8,"type_name":"Item3","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"itemimg":[{"image":"1524568505IMG_0344.PNG"},{"image":"1525761327virtual_closet_mobile.jpg"}]},{"id":424,"type":"editoutfits","type_id":5,"datetime":"2018-05-08T05:44:08","status":1,"user_id":8,"type_name":"Test","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"oufitimg":"1525758248newlookImage.jpg"},{"id":421,"type":"editoutfits","type_id":5,"datetime":"2018-05-08T05:38:41","status":1,"user_id":8,"type_name":"Test","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"oufitimg":"1525758248newlookImage.jpg"},{"id":418,"type":"editoutfits","type_id":5,"datetime":"2018-05-08T05:38:29","status":1,"user_id":8,"type_name":"Test","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"oufitimg":"1525758248newlookImage.jpg"},{"id":355,"type":"editoutfits","type_id":5,"datetime":"2018-05-03T05:44:22","status":1,"user_id":8,"type_name":"Test","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"oufitimg":"1525758248newlookImage.jpg"},{"id":353,"type":"edititem","type_id":10025,"datetime":"2018-05-02T12:03:54","status":1,"user_id":8,"type_name":"Item1","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"itemimg":[{"image":"1524201903virtual_closet_mobile.jpg"},{"image":"1524201903IMG_0190.PNG"}]},{"id":351,"type":"editoutfits","type_id":5,"datetime":"2018-05-02T05:48:26","status":1,"user_id":8,"type_name":"Test","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"oufitimg":"1525758248newlookImage.jpg"},{"id":283,"type":"addoutfits","type_id":8,"datetime":"2018-04-24T12:26:24","status":1,"user_id":6,"type_name":"Testttttt","user":{"username":"user2","id":"6","first_name":"sonam","last_name":"dogra"},"user_meta":{"value":"1524139232IMG_0186.PNG"},"oufitimg":"1524572784newlookImage.jpg"},{"id":250,"type":"additem","type_id":10034,"datetime":"2018-04-24T11:15:05","status":1,"user_id":8,"type_name":"Item3","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"itemimg":[{"image":"1524568505IMG_0344.PNG"},{"image":"1525761327virtual_closet_mobile.jpg"}]},{"id":235,"type":"editoutfits","type_id":3,"datetime":"2018-04-24T10:18:03","status":1,"user_id":8,"type_name":"Outfit1","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"oufitimg":"1525261115newlookImage.jpg"},{"id":232,"type":"addoutfits","type_id":5,"datetime":"2018-04-24T10:17:49","status":1,"user_id":8,"type_name":"Test","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"oufitimg":"1525758248newlookImage.jpg"},{"id":225,"type":"addoutfits","type_id":3,"datetime":"2018-04-24T10:10:26","status":1,"user_id":8,"type_name":"Outfit1","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"oufitimg":"1525261115newlookImage.jpg"},{"id":207,"type":"likeitem","type_id":10026,"datetime":"2018-04-23T12:46:53","status":1,"user_id":8,"type_name":"Item2","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"}},{"id":206,"type":"itemcomment","type_id":10032,"datetime":"2018-04-23T12:35:29","status":1,"user_id":8,"type_name":"","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"}},{"id":190,"type":"additem","type_id":10026,"datetime":"2018-04-20T05:31:30","status":1,"user_id":8,"ty"type_name":"Item2","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"itemimg":[{"image":"1524202290IMG_0125.PNG"},{"image":"1524202290virtual_closet_mobile.jpg"},{"image":"1524202290virtual_closet_mobile.jpg"}]},{"id":187,"type":"additem","type_id":10025,"datetime":"2018-04-20T05:25:03","status":1,"user_id":8,"type_name":"Item1","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"},"itemimg":[{"image":"1524201903virtual_closet_mobile.jpg"},{"image":"1524201903IMG_0190.PNG"}]},{"id":60,"type":"acceptrequest","type_id":8,"datetime":"2018-04-19T17:23:46","status":1,"user_id":8,"type_name":"","user":{"username":"user4","id":"8","first_name":"ruhi","last_name":"vohra"},"user_meta":{"value":"1524139730IMG_0189.JPG"}}],"result":"success","image_path":"img\\/users"}