Link to home
Start Free TrialLog in
Avatar of rgarimella
rgarimella

asked on

Spliting a String

Hi Folks

I have the following string

var data = "{"CTS":"0,51,52","lastTopic":53,"questions_answered":["3","2","4","1","9"],"scoreArray":[],"06_01":20}"

Open in new window


How do I get the value of 06_01 which is 20

I need the value of 06_01 (which in this case is 20)

Thanks

RG
Avatar of leakim971
leakim971
Flag of Guadeloupe image

var data = '{"CTS":"0,51,52","lastTopic":53,"questions_answered":["3","2","4","1","9"],"scoreArray":[],"06_01":20}';

// work on modern browser, check this page : http://caniuse.com/#search=JSON.parse
// for old browser download and include the following javascript in your page :
// https://github.com/douglascrockford/JSON-js/blob/master/
// <script type="text/javascript" src="path/to/your/js/folder/json_parse.js" ></script>
var json = JSON.parse(data); 

alert( json["06_01"] );

Open in new window

Avatar of rgarimella
rgarimella

ASKER

How would I code for older browsers especially IE7 ?

It works for the rest
read the code in my first post, line 4,5,6...
Sorry, I read the above lines for older browser. Confusion was in the json_parse.js, the sample code was like this

myData = json_parse(text, function (key, value) {..

Open in new window


your code was

var json = JSON.parse(data); 

Open in new window


Also do I have to detect older browsers ?
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial