JSON.parse从Web API返回未定义

时间:2019-07-08 12:03:58

标签: json react-native react-native-android

当我尝试使用JSON.parse()时不会返回任何内容。

fetch(
      "SOMEWEBSERIVCE!!!!!!!!!",
      {
        method: "POST",
        headers: new Headers({
          Accept: "application/json",
          "Content-type": "application/json" // <-- Specifying the Content-Type
        })
      }
    )
      .then(Response => Response.text())
      .then(x => {
        const str = x.substring(6);
        const str4 = str.substring(0, str.length - 2);
        const str5 = str4.replace(/\\/g, "");
        console.log("str5", str5);
        const dateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
        function reviver  (value){
          if(typeof value==="string"&&dateFormat.test(value)){
            return new Date(value);

          }
          return value;
        }
        const str3 = JSON.parse(str5,reviver);

        console.log("str3", {str3});
        dispatch({ type: FETCH_CHECKLIST_SUCCESS, payload: str3 });
      })

str5 is returning string this output on console:
[{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"1","Rihtim":1,"Gemi_Sefer_No":"1","Checklist_Kod":1,"ID":4,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"bir","Rihtim":3,"Gemi_Sefer_No":"deneme","Checklist_Kod":2,"ID":6,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"bir","Rihtim":3,"Gemi_Sefer_No":"deneme","Checklist_Kod":2,"ID":7,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"bir","Rihtim":5,"Gemi_Sefer_No":"test","Checklist_Kod":2,"ID":8,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"bir","Rihtim":5,"Gemi_Sefer_No":"testtat","Checklist_Kod":2,"ID":9,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"2","Rihtim":1,"Gemi_Sefer_No":"1","Checklist_Kod":1,"ID":10,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"5","Rihtim":5,"Gemi_Sefer_No":"5","Checklist_Kod":5,"ID":11,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"1","Rihtim":1,"Gemi_Sefer_No":"1","Checklist_Kod":1,"ID":12,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"4","Rihtim":4,"Gemi_Sefer_No":"4","Checklist_Kod":4,"ID":13,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":""123"","Rihtim":123,"Gemi_Sefer_No":""asdd"","Checklist_Kod":2,"ID":14,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"123","Rihtim":123,"Gemi_Sefer_No":"123","Checklist_Kod":123,"ID":15,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"4","Rihtim":2,"Gemi_Sefer_No":"1","Checklist_Kod":2,"ID":16,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"4","Rihtim":2,"Gemi_Sefer_No":"1","Checklist_Kod":2,"ID":17,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"11","Rihtim":22,"Gemi_Sefer_No":"33","Checklist_Kod":13,"ID":1017,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"biadr","Rihtim":54451,"Gemi_Sefer_No":"testasdadtat","Checklist_Kod":22,"ID":1018,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"biadr","Rihtim":54451,"Gemi_Sefer_No":"testasdadtat","Checklist_Kod":22,"ID":1019,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"123","Rihtim":33,"Gemi_Sefer_No":"123","Checklist_Kod":11,"ID":1020,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"biadr","Rihtim":54451,"Gemi_Sefer_No":"testasdadtat","Checklist_Kod":22,"ID":1021,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"ffffadr","Rihtim":54451,"Gemi_Sefer_No":"testasdadtat","Checklist_Kod":22,"ID":1022,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"ttttttiadr","Rihtim":54451,"Gemi_Sefer_No":"testasdadtat","Checklist_Kod":22,"ID":1023,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"ttttttiadr","Rihtim":54451,"Gemi_Sefer_No":"testasdadtat","Checklist_Kod":22,"ID":1024,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"biadr","Rihtim":54451,"Gemi_Sefer_No":"testasdadtat","Checklist_Kod":22,"ID":1025,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]},{"Tarih":"2019-07-08T00:00:00+03:00","Vardiya":0,"Liman":"biadr","Rihtim":13451,"Gemi_Sefer_No":"testasdadtat","Checklist_Kod":313,"ID":1026,"Approval":0,"Approval_Name":null,"Approval_Date":null,"Bekleme_Log":[],"Checklist_Log":[],"Ekipman_Log":[],"Checklist_Upload":[],"CL_VA_Rihtim_Dty":[]}]

在解析此str5 str3之后,BUT返回未定义。

0 个答案:

没有答案