In Firefox, the following code works with "arry = eval(json1);" in the
penultimate line but fails with a Firebug json.parse error when "arry =
JSON.parse(json1);" is used. I guess I've been staring at this too long,
what is upsetting JSON.parse()?
var json1 = {
"id":37008,
"natoms":1000,
"nframes":1000,
"atomType":[0,1],
"frames":
[{
"position":[[10.1,20.1,30.1], [20.1,30.1,30.1]],
"charge":[0.5, 4.3],
"nbonds":1,
"bonds":[0,1]
}]
}
arry = JSON.parse(json1);
window.alert(arry.frames[0].position[1][1]);
|
|
0
|
|
|
|
Reply
|
SteveYoungTbird
|
12/22/2010 6:44:10 PM |
|
On 12/22/2010 07:44 PM, SteveYoungTbird wrote:
> In Firefox, the following code works with "arry = eval(json1);" in the
> penultimate line but fails with a Firebug json.parse error when "arry =
> JSON.parse(json1);" is used. I guess I've been staring at this too long,
> what is upsetting JSON.parse()?
>
> var json1 = {
> "id":37008,
> "natoms":1000,
> "nframes":1000,
> "atomType":[0,1],
> "frames":
> [{
> "position":[[10.1,20.1,30.1], [20.1,30.1,30.1]],
> "charge":[0.5, 4.3],
> "nbonds":1,
> "bonds":[0,1]
> }]
> }
> arry = JSON.parse(json1);
> window.alert(arry.frames[0].position[1][1]);
Stupid of me. The variable json1 is already an object and therefore it
doesn't need parsing, "window.alert(json1.frames[0].position[1][1]);" works.
|
|
0
|
|
|
|
Reply
|
SteveYoungTbird
|
12/22/2010 9:03:43 PM
|
|
|
1 Replies
502 Views
(page loaded in 0.303 seconds)
|