I have a web service that returns a serialized JSON data string. An example of what is returned is:
{"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"}
two sets of the same data seperated by a comma. now i have this code harded coded in my controller and it loads fine. my code that sets the scope variable.
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;
});
Key Line
$scope.students = [JSON.parse(parsedResponse)];
debugger just says syntax error. now this code works fine for one set of data. but not more than one.
Please help Thanks joe