Solved

Spliting a String

Posted on 2013-01-14
6
220 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How does Redux fit into React? 3 67
Allow space in this pattern 2 47
Basic JavaScript Question 3 38
Creating a dynamic URL - set dates to upcoming weekend 6 30
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now