Leo
Leo

Reputation: 14820

Bad json response when calling Parse cloud function

I've been using Parse's REST API for quite a while, but now in an attempt to reduce the amount of requests made to Parse's servers I've started exploring the Cloud Code features which looks quite nice -based on what I've read so far. The fact that you define and run some business logic on Parse's servers looks like a very powerful tool.

However, I haven't even been able to get the basics up and running. I followed this Getting Started Guide but I got stuck when trying to call the "hello" function on the background. Here's what I've done:

  1. Imported the jar files into the Android Studio project
  2. Install Parse's powershell command tool
  3. Created a cloud code directory locally. By default, it creates the hello function in "main.js"
  4. Deployed it
  5. Run a test on my Android app by call this hello function but it fails to parse the response

Here's the stacktrace of the error:

11-26 08:28:44.499  18299-18299/com.package.appname E/Leo_Debug﹕ Error: bad json response: org.json.JSONException: Value Invalid of type java.lang.String cannot be converted to JSONObject
com.parse.ParseException: bad json response: org.json.JSONException: Value Invalid of type java.lang.String cannot be converted to JSONObject
com.parse.ParseException: bad json response: org.json.JSONException: Value Invalid of type java.lang.String cannot be converted to JSONObject
        at com.parse.ParseRequest.connectionFailed(ParseRequest.java:415)
        at com.parse.ParseCommand.onResponse(ParseCommand.java:387)
        at com.parse.ParseCommand.onResponse(ParseCommand.java:36)
        at com.parse.ParseRequest$3.call(ParseRequest.java:295)
        at bolts.Task$2.run(Task.java:195)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:841)

This is the cloud code function I'm calling...

Parse.Cloud.define("hello", function(request, response) {
  response.success("Hello world!");
});

And this is how I'm making to the call to the function using the Parse SDK for Android...

String clientId = ctx.getString(R.string.parse_app_id);
String clientKey = ctx.getString(R.string.parse_app_api_key);
Map<String,Object> map = new HashMap<String, Object>();

Parse.initialize(ctx, clientId, clientKey);
ParseCloud.callFunctionInBackground("hello", map, new FunctionCallback<String>() {
        public void done(String o, ParseException e) {
            if(e != null) {
                Utils.LogError(e);
            }
            else{
                Utils.Log("ParseCloud.hello: " + o);
            }
        }
});

The ctx variable is an instance of the "Context" class and Utils it's just a helper class I used when debugging is turn on to print use info to the LogCat.

I haven't been able to find much information around neither on their old Forums Site nor on their dedicated Google Groups. If anyone ran into this issue before any help would be greatly appreciated

Upvotes: 1

Views: 1445

Answers (1)

Mullazman
Mullazman

Reputation: 509

Using Android Studio I was using compile 'com.parse:parse-android:1.+' which was perfectly fine until yesterday. After many attempts at all sorts, I found changing this to compile 'com.parse:parse-android:1.12 got rid of this error. So check your library references!

Upvotes: 2

Related Questions