html - Help with JSON raw format in javascript - Stack Overflow

I have a JSON array of data which is [ [[2, 5], [6, 10], [10, 7], [11, 15]],[[0, 9], [1, 16], [3, 19],

I have a JSON array of data which is

[ [[2, 5], [6, 10], [10, 7], [11, 15]],
  [[0, 9], [1, 16], [3, 19], [4,  15]],
  [[0, 7], [5, 16], [8, 17], [12, 19]] ]

but when I try to get the first array of [[2, 5], [6, 10], [10, 7], [11, 15]] using jsonData[0] I get the data as 2,5,6,10,10,7,11,15.

I would like to get the data in the JSON format and not the plain text format. Any ideas?

I have a JSON array of data which is

[ [[2, 5], [6, 10], [10, 7], [11, 15]],
  [[0, 9], [1, 16], [3, 19], [4,  15]],
  [[0, 7], [5, 16], [8, 17], [12, 19]] ]

but when I try to get the first array of [[2, 5], [6, 10], [10, 7], [11, 15]] using jsonData[0] I get the data as 2,5,6,10,10,7,11,15.

I would like to get the data in the JSON format and not the plain text format. Any ideas?

Share Improve this question edited Aug 27, 2010 at 23:49 John Kugelman 363k69 gold badges553 silver badges597 bronze badges asked Aug 27, 2010 at 23:33 SanaSana 9,92516 gold badges60 silver badges87 bronze badges 1
  • I get what you'd expect using identical syntax, perhaps show us a bit more...the problem must be further along in your code. – Mark Elliot Commented Aug 27, 2010 at 23:37
Add a ment  | 

2 Answers 2

Reset to default 3

You should get the data as an array. Did you alert jsonData[0] because that will display the results as a flattened string.

Instead console.log(jsonData[0]) to see the actual array.

Here's the output I see when using your array.

var a = [[[2, 5], [6, 10], [10, 7], [11, 15]],[[0, 9], [1, 16], [3, 19], [4, 15]],[[0, 7], [5, 16], [8, 17], [12, 19]]];

alert(a[0]);       // 2,5,6,10,10,7,11,15

console.log(a[0]); // [[2, 5], [6, 10], [10, 7], [11, 15]]

See an example.

Also, "JSON raw format" is misleading. What you have is a plain JavaScript array.

Are you asking how to convert it to a JSON string rather than simply getting the default toString behaviour of an array? If so you should just do:

JSON.stringify(jsonData[0])

Or whatever it is you want to stringify

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745306298a4621730.html

相关推荐

  • html - Help with JSON raw format in javascript - Stack Overflow

    I have a JSON array of data which is [ [[2, 5], [6, 10], [10, 7], [11, 15]],[[0, 9], [1, 16], [3, 19],

    6小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信