react native- json parsing (cant parse json object in my code)

json parse error: unexpected identifier try
at json parse anonymous
json parse invalid character
json parse error: unexpected identifier undefined

Here is my code. In this I got x but when I try to parsing x for getting object of x 'isloggedin' it gives error. what should I do wrong tell me if you understand my problem.

componentDidMount() {
    this.onLoad();
  }
 onLoad = async () => {
    try {
        var walletdata = await AsyncStorage.getItem('wallet');
        this.setState({x: JSON.parse(walletdata)})
        this.setState({y: JSON.stringify(this.state.x)})
        console.log("output:  "+ this.state.y);
        console.log("output y:"+JSON.parse(this.state.y.isloggedIn));
      }catch(error){
        console.log("error: "+error);
      }
  }

error: SyntaxError: JSON Parse error: Unexpected identifier "undefined"

Probably is because 'wallet' key has undefined value in the caché storage. You should check first the value (right after getting the item from the storage) and if it's undefined then you have to set it first.

Here is my code. In this I got x but when I try to parsing x for getting object of x '​isloggedin' it gives error. what should I do wrong tell me if you understand my  Parse JSON from a local file in react-native: JSON or JavaScript Object Notation is a widely used format for transferring data. For example, a server can return data in JSON format and any frontend application (Android, iOS or Web application) can parse and use it.

Probably you need to wait for the first setState function to finish, So that you can get access to it in second call.

In short, It will take some time for setting your value in State and you are trying to access it before updating the state. So try to access the values in the callback of setState function.

Instead of this,

this.setState({x: JSON.parse(walletdata)})
this.setState({y: JSON.stringify(this.state.x)})
console.log("output:  "+ this.state.y);
console.log("output y:"+JSON.parse(this.state.y.isloggedIn));

You can use this:

this.setState({x: JSON.parse(walletdata),y: JSON.stringify(walletdata.x)},()=>{
        console.log("output:  "+ this.state.y);
        console.log("output y:"+JSON.parse(this.state.y.isloggedIn));
});

React Native version: 0.60.3 Steps To Reproduce upgrade react native to to host and review code, manage projects, and build software together. MasoudAlali changed the title [60.3] fetch issue [60.3] fetch issue [unable to parse json, Fetch response.text() gives responseData =[Object Blob] #26015. Array as JSON. When using the JSON.parse() on a JSON derived from an array, the method will return a JavaScript array, instead of a JavaScript object.

I have solved my problem. Thank you for your answers. below is how could I solved my question.

 try {
            var walletdata = await AsyncStorage.getItem('wallet');
            this.setState({wallet: JSON.stringify(JSON.parse(walletdata))})                
            this.setState({isLoggedin:JSON.parse 
                 (this.state.wallet).isLoggedin});
            console.log(this.state.isLoggedin);
        }catch(error){
            console.log("error: "+error);
        }

I've seen previous Github issues in the past involving JSON parsing Fixed this by removing these fields from my Headers object. Hi, I have this problem JSON parser error: unrecognized token '<' in react native. my code is  When it detects invalid JSON, it throws a JSON Parse error. For example, one of the most common typos or syntax errors in JSON is adding an extra comma separator at the end of an array or object value set. Notice in the first few examples above, we only use a comma to literally separate values from one another.

I want to just extract the product name for the JSON object I get back. I can print to console and I get the following JSON object: Here's the code on the page: import React from 'react' export default class Products extends React. I don't have enough background outside of vanilla JS to understand this. React Native Create FlatList using JSON Parsing Data Example Tutorial admin September 20, 2017 September 20, 2017 React Native FlatList is the advance version of ListView with more user handy features like it is fully cross platform and dose support both Android and iOS mobile phone devices.

The JSON.parse() method parses a JSON string, constructing the See the JSON object for a description of JSON syntax. reviver From https://github.com/​douglascrockford/JSON-js/blob/master/json2.js if (typeof JSON.parse  JSON Parser Online helps to parse, view, analyze JSON data in Tree View. It's a pretty simple and easy way to parse JSON Data and Share with others. This Parse JSON tool is very powerful.

The promise rejects if the fetch was unable to make HTTP-request, status – HTTP status code, e.g. 200. ok – boolean, true if the HTTP status code is 200-299​. For instance, let's get a JSON-object with latest commits from GitHub: body consumed let parsed = await response . json ( ) ; // fails (already  In the API docs you write: parse: from input to store. format: from store to output. I think by "input" you mean the values parameter that goes into the form object. By "output" you mean what I get when the form is submitted. It doesn't