【发布时间】:2015-03-13 18:52:07
【问题描述】:
我有一个返回序列化 JSON 数据字符串的 Web 服务。返回的示例如下:
{"Campus":"BMSB","Program":null,"Selected":"false","Status":"NEW","Status2":null ,"Status3":null,"StudentID": 00000,"StudentFirstName":"Ioneu0027a","StudendMiddle Name":"","StudentLastName":"Byra"}, {"Campus":"BMFW","Program":"Accounting- Diploma","Selected":"false","Status":"GRAD","Status2":"GRAD","Status3":null," StudentID":00000,"StudentFirstName":"Kathryn","StudendMiddleName":"I","StudentLastName":"Eib"}
两组相同的数据,用逗号分隔。 现在我在我的控制器中硬编码了这段代码,它加载得很好。 我设置范围变量的代码。
soaFactory.getStudent(studentnumber,carslocation)
.success(function (response){
if(JSON.parse(response) == "Object reference not set to an instance of an object.")
{
//this code will hide any previous student info if a student is not returned
$scope.noStudentReturned = false;
$scope.students = null;
$scope.curStudentFirstName= null;
$scope.curStudentLastName = null;
$scope.curStudentSchool= null;
$scope.curStudentStatus= null;
$scope.curStudentProgram= null;
}
else
{
var parsedResponse= JSON.parse(response);
//alert("parsedResponse :" + parsedResponse );
//var parsedAgain= JSON.parse(parsedResponse);
// alert("parseAgain: " + parsedResponse);
// $scope.students = [parsedResponse];
$scope.students = [JSON.parse(parsedResponse)];
$scope.noStudentReturned = true;
if ($scope.students.length == 1)
{
//if only one student returned call this function.
$scope.setStudent(e,0);
}
else
{
}
}
})
.error(function (error){
alert(error);
$scope.noStudentReturned = false;
$scope.students = null;
$scope.curStudentFirstName= null;
$scope.curStudentLastName = null;
$scope.curStudentSchool= null;
$scope.curStudentStatus= null;
$scope.curStudentProgram= null;
});
关键线
$scope.students = [JSON.parse(parsedResponse)];
调试器只是说语法错误。 现在这段代码适用于一组数据。但不超过一个。
请帮忙 谢谢 乔
【问题讨论】: