我想一个JSON对象发送到我的apiController:JSON阵列,quotaions标记
myJson对象,我构建dynamicaly这样的:
var course= new Object();
course.info= $scope.info;
course.studentList = [];
course.studentList = $scope.results;
$ scope.results是一个数组我从我的观点得到:
<select ng-model="results[$index]" >
<option value=""></option>
<option ng-repeat="r in myList" value={{r}}>{{r.studlastname}}</option>
</select>
我的期望:
{
"course": {
"courseName":"yyy",
"courseDesc":"xxxx",
"prof":"prof1"
},
"studentList" :[
{"studfirstname":"2","studlastname":"","studAge":"21"},
{"studfirstname":"4","studlastname":"","studAge":"40"},
{"studfirstname":"6","studlastname":"","studAge":"60"}
]
}
我有:
{
"course": {
"courseName":"yyy",
"courseDesc":"xxxx",
"prof":"prof1"
},
"studentList" :[
"{"studfirstname":"2","studlastname":"","studAge":"21"}",
"{"studfirstname":"4","studlastname":"","studAge":"40"}",
"{"studfirstname":"6","studlastname":"","studAge":"60"}"
]
}
通知每个studentList元素上的报价,这是在服务器端反序列化造成的问题。
请你能帮我删除报价吗?
谢谢你提前。
嗨Wasif, 我已经尝试过这一点,但它给我这个错误: **语法错误:意外的标记,在JSON位置112处** – anonymouslyGeek
是的,它是给错误作为你的JSON是无效的。你能告诉我这是ng-model的价值吗? {“studfirstname”:“2”,“studlastname”:“”,“studAge”:“21”}对不对? 这是无效的JSON,如果你尝试将它添加到变量来解析它。它应该像引用转义,在JSON对象中解析 示例: var v =“{\”studfirstname \“:\”2 \“,\”studlastname \“:\”\“,\”studAge \“: \ “21 \”}“; 然后你可以做这样的事情: JSON.parse(v); –
正是我想要做的,但我无法弄清楚如何逃避这些引号! – anonymouslyGeek