4

I have a string in a div element like this:

['39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78', '39.55,115.78']

I want get this list object using jQuery in Internet Explorer. What can I do?

2
  • r u getting same value again and again? '39.55,115.78' Commented Mar 5, 2011 at 7:39
  • Do you want to access its elements as just strings like '39.55,115.78' or the individual numbers like 39.55 and 115.78? Commented Mar 5, 2011 at 8:54

2 Answers 2

3
$.parseJSON($("#yourDiv").text())

However, JSON requires that you use double-quotes, whereas you are using single-quotes in your example. If you want to parse it anyway, you could replace them in your string:

$.parseJSON($("#yourDiv").text().replace(/'/g, "\""))
Sign up to request clarification or add additional context in comments.

3 Comments

AFAIK parseJSON works with json string...is it json string written in question??
No, because it uses single-quotes instead of double-quotes. However, since the question is tagged "json" and includes "json" in the title I decided that this was probably the answer he would prefer. :)
Isn't your replace backwards?
2

Read this...

http://api.jquery.com/jQuery.parseJSON/

It looks like you string is not a well formed jSON string.

EDIT: and this... http://www.json.org/example.html

1 Comment

+1 for knowing the JSON syntax - a rare thing these days - see comments to this answer. ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.