Problem Statement
I'm trying to create an array with another array inside this array, but it doesn't work for me.
This is what i wrote:
var arr = '{"project":['
+ '{"id":"01","name":"project1","activity":['
+ '{"num":"001","time":"7","desc":"desc","stam":['
+ ' "pre":"005","pre2":"002"]}'
+ '{"num":"002","time":"6","desc":"desc"}'
+ '{"num":"003","time":"5","desc":"desc"}'
+ '{"num":"004","time":"4","desc":"desc"}'
+ '{"num":"005","time":"3","desc":"desc"}]}]}';
Marcos Pérez Gude
22.2k4 gold badges41 silver badges70 bronze badges
2 Answers 2
Your JSON looks corrupted. You can use several online editors and validators to verify the JSON string. editor and validator just as an example of mony others. You also might have a look here.
,is missing between the array elements- the property
stamlooks more like an object than an array
It should look like this:
{"project":[
{"id":"01","name":"project1","activity":
[
{"num":"001","time":"7","desc":"desc","stam":{
"pre":"005",
"pre2":"002"
}
},
{"num":"002","time":"6","desc":"desc"},
{"num":"003","time":"5","desc":"desc"},
{"num":"004","time":"4","desc":"desc"},
{"num":"005","time":"3","desc":"desc"}
]
}
]
}
answered Dec 2, 2015 at 11:25
frank
1,2472 gold badges10 silver badges18 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
The json is not formatted correctly:
{
project : [{
id : "01",
name: "project1",
activity :[
{
num : "001",
time : "7",
desc : "desc",
stam : [{
pre : "005",
pre2: "002"
}]
},
{
num : "002",
time: "6",
desc: "desc"
},
{
num : "003",
time: "5",
desc:"desc"
},
{
num : "004",
time: "4",
desc: "desc"
},
{
num : "005",
time: "3",
desc: "desc"
}
]
}]
}
answered Dec 2, 2015 at 11:33
John Roca
1,2442 gold badges16 silver badges29 bronze badges
Comments
lang-js
JSON.stringify.