php - JSON.parse not working on older mobile browsers -


i have json string a. in format:

'[{"key1":"val1",...,"keyn":"valn"},{...},...,{...}]' 

a created on php server using json_encode(array).

var str = json.parse(a); works in desktop browsers, mobile safari, mobile chrome etc..

var str = json.parse(a); throws exception('exception: cannot parse string') in android 2.2 default browser , black berry devices' browers.

json.parse works in browser not json string a. there bug in json parser on browser?

edit. if put textarea , copy , paste string directly javascript code.. json.parse('[{"key1":"val1",...,"keyn":"valn"},{...},...,{...}]') works.

but, doesn't work -> json.parse($('div').html(a).text());

the older json.parse parse object....

try surround below...

'{ "data" : [{"key1":"val1",...,"keyn":"valn"},{...},...,{...}] }' 

if not work... can try

function getobj(json){   return (new function(" return (" + json + "); "))(); }  var value = getobj('[{"key1":"val1",...,"keyn":"valn"},{...},...,{...}]'); 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -