Solved

Spliting a String

Posted on 2013-01-14
6
219 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
Comment Utility
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
Comment Utility
0
 

Author Comment

by:rgarimella
Comment Utility
How would I code for older browsers especially IE7 ?

It works for the rest
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 82

Expert Comment

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

Author Comment

by:rgarimella
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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. …
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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…

743 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

16 Experts available now in Live!

Get 1:1 Help Now