Android : Uable to get JSON in cloud function callback android

on Thursday, January 29, 2015


I am working on Parse platform (Parse.com) in which I have a cloud code function written below which returns me proper JSON response in result -


Cloud function -



Parse.Cloud.define("getBranchbyUniversityID", function(request, response) {
var branchList = { Branch: [] };
var universityID = request.params.UniversityID;
console.log("University ID received " + universityID);
var TableBranch = Parse.Object.extend("TableBranch");
var query = new Parse.Query(TableBranch);
query.equalTo("UniversityId", universityID);
query.find({
success: function (results) {
var branchDetails_length = results.length;
console.log("branchDetails_length " + branchDetails_length);
if (branchDetails_length > 0) {
for (var i = 0; i < branchDetails_length; i++) {
var branchName = results[i].get("BranchName");
var branchID = results[i].get("BranchId");
branchList.Branch.push({
"BranchName" : branchName,
"BranchId" : branchID
});
}
}
response.success(branchList);
},
error: function (error) {
response.error("Could not connect to server");
}
});
});


Result that i get in my parse log console



{
"Branch":[
{
"BranchName":"Civil",
"BranchId":"2"
},
{
"BranchName":"ComputerScience",
"BranchId":"1"
}
]
}


My Android code to call cloud function "getBranchbyUniversityID"



String uniId = "1";

Map<String,Object> params = new HashMap<String, Object>();
params.put("UniversityID",uniId);

ParseCloud.callFunctionInBackground("getBranchbyUniversityID", params, new FunctionCallback<Object>() {
@Override
public void done(Object response, ParseException e) {
LoggingUtil.log("Response for BranchDetails", response.toString());

}
});


This is what my log console print in android



Response for BranchDetails﹕ {Branch=[{BranchName=Civil, BranchId=2}, {BranchName=ComputerScience, BranchId=1}]}


The response i am getting is not in the form of JSON but i can see in the parse console the Result is in JSON as mentioned above.


I also tried also tried calling cloud function like



ParseCloud.callFunctionInBackground("getBranchbyUniversityID", params, new FunctionCallback<JSONObject>()


but this also did not worked it was giving class exception.


Can anyone tell me what am i doing wrong or is it the SDK problem ?


0 comments:

Post a Comment