I'd like to consume an API (Python Django) that produce data under 'String' JSON format.
Is there an option to recognize it automatically as a JavaScript object with JQuery?
I'd like to consume an API (Python Django) that produce data under 'String' JSON format.
Is there an option to recognize it automatically as a JavaScript object with JQuery?
You'll want to use jQuery.parseJSON() please follow the link for full details.
I'm assuming here, that you are getting a proper JSON string.
Depends on your definition of "automatically". If you mean you want the code to interpret the response as JSON without explicitly telling the code to interpret the response as JSON, then the answer is no.
What you probably want to do is abstract ajax into a function that makes the assumptions you want to make.
if your json string as below
'{"a":0,"b":"text"}'
only with JS native
var _string = '{"a":0,"b":"text"}';
console.log(JSON.parse(_string));