P
P
Pavel Chuev2017-05-23 18:17:22
JSON
Pavel Chuev, 2017-05-23 18:17:22

Crooked JSON response?

I am writing an application in react-native and ran into the following problem:
It is required to display the schedule by specifying the route for the train.
Here is a piece of code that I use to call the js script (it will be below) in order to pull out the schedule itself by the name of the stations.

api(froms).then(
      (data) => {

        if(data.doc){
          var value = this.state.dataSource.cloneWithRows(data.doc.value);

          this.setState({
            hasResult: true,
            noResult: false,
            result: data.doc,
            value: value,
            isLoading: false
          });

          var type_names = _.map(data.doc.value, function(type){
             return type.value;
          });
        }else{
          
          this.setState({
            hasResult: false,
            noResult: true,
            isLoading: false,
            result: null
          });

        }
      }
    );

Here is the js code for working with the server:
module.exports = function(froms){

    var url = 'http://awgfawfwafawf.awfa/train/get.php?from=' + froms;

    return fetch(url).then(function(response){
        return response.json();
    }).then(function(json){
        return json;
    });
}

There is a response from the server and looks like this (Couch DB):
{"id":"2cc939baf01d563ff36bc878a217feea",
"key":"Подлипки-Дачные",
"value":"Москва (Ярославский вокзал) — Монино",
"doc":{"_id":"2cc939baf01d563ff36bc878a217feea","_rev":"1-9aac915114795ba2ca720bbba8bbd201",
"title":"Москва (Ярославский вокзал) — Монино","from":"Подлипки-Дачные",
"to":"Монино","departure":"2017-05-23 00:47:00","arrival":"2017-05-23 01:28:00","stops":"везде"}}

I don't understand where the problem could be. React server console says invalid JSON.
I hope for some advice in solving this problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2017-05-23
@vshvydky

judging by what I see, you do not need to parse this object, since this is not a json string, but a js object

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question