我有一个Web服务,它返回一个序列化的JSON数据字符串。返回的例子是:
{“Campus”:“BMSB”,“Program”:null,“Selected”:“false”,“Status”:“NEW”,“Status2”:null ,“Status3”:null,“StudentID”:00000,“StudentFirstName”:“Ioneu0027a”,“StudendMiddle Name”:“”,“StudentLastName”:“Byra”}, {“Campus”:“BMFW” “:”Accounting-Diploma“,”Selected“:”false“,”Status“:”GRAD“,”Status2“:”GRAD“,”Status3“:null,”StudentID“:00000,”StudentFirstName“ “,”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)];
调试器只是说语法错误。 现在这个代码对于一组数据工作正常。但不超过一个。
请帮 感谢 乔
这是不正确的。 JSON允许使用整数,浮点数,空值,字符串(双引号)和布尔值(http://json.org/) – goreorto 2015-03-14 00:13:19
将null作为无引号的值进行尝试,它将很好地解析。至少由一些口译员使用字符串值也是如此,这就是为什么我说你可能会逃避它。我们不是说一些不同的东西,除非你提到的布尔值不一定用双引号。 – alou 2015-03-14 17:10:34