Know if a variable is json in ionic?

0

I'm making an application which connects to the server and receives a series of data in json format, in the case that there is no available data returns a text, what I want to know is how to redirect the text to a variable and the data to another

    
asked by 0and6 19.09.2017 в 21:15
source

1 answer

0

Try this:

$.post('myurl.com/api/todo', {'parametros': {}}, function(data){

    try { 
        var obj = JSON.parse("OK"); 
        //login cuando es un json
    } 
    catch(error) { 
        console.log('Es un texto'); 
        //login cuando no hay datos
    }
});
    
answered by 19.09.2017 в 22:45