Solved

Spliting a String

Posted on 2013-01-14
6
224 Views
Last Modified: 2013-01-15
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
0
Comment
Question by:rgarimella
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 38776837
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

0
 
LVL 82

Expert Comment

by:leakim971
ID: 38776858
0
 

Author Comment

by:rgarimella
ID: 38779126
How would I code for older browsers especially IE7 ?

It works for the rest
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Expert Comment

by:leakim971
ID: 38779152
read the code in my first post, line 4,5,6...
0
 

Author Comment

by:rgarimella
ID: 38779392
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 ?
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38779500
Also do I have to detect older browsers ?

no, just add the script if you want to support them and use :

JSON = JSON?{parse:json_parse}:JSON;
var json = JSON.parse(data);
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question