Skip to content

bad json response issue, cant figure out why. #5116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mginz83 opened this issue Oct 10, 2018 · 6 comments
Closed

bad json response issue, cant figure out why. #5116

mginz83 opened this issue Oct 10, 2018 · 6 comments

Comments

@mginz83
Copy link

mginz83 commented Oct 10, 2018

I have two functions that this is happening to...

First

Parse.Cloud.define("GetKeys", function(request, response) {

  var appKey = "APP_KEY";
  var singleKey = "SINGLE_KEY";

  var jsonObject = {
    "appkey": appKey,
    "singleKey" : singleKey
  };
  success: function() {
  	response.success(jsonObject);
  }
  
}, { useMasterKey: true });

I get a bad json response for this.

Here is my call...

HashMap<String, Object> params = new HashMap<String, Object>();
                ParseCloud.callFunctionInBackground("GetKeys", params, new FunctionCallback<Map<String, Object>>() {
                    public void done(Map<String, Object> mapObject, ParseException e) {
                        if (e == null) {

                            appKey = mapObject.get("appkey").toString();
                            singleKey = mapObject.get("singleKey").toString();

                            SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences(SHARED_PREF, MODE_PRIVATE);
                            SharedPreferences.Editor editor = sharedPreferences.edit();
                            editor.putString("appKey", appKey);
                            editor.putString("singleKey", singleKey);
                            editor.apply();
                            doInBackground();


                        } else {
                            //log error
                        }
                    }
                });

I also have this cloud functions as well...

Parse.Cloud.define("SaveSearchByDevice", function(request, response) {

const UserSearch = Parse.Object.extend("UserSearch");
const userSearch = new UserSearch();

userSearch.set("deviceManufacturer", request.params.deviceManufacturer);
userSearch.set("deviceModel", request.params.deviceModel);
userSearch.set("deviceRelease", request.params.deviceRelease);
userSearch.set("deviceSDKName", request.params.deviceSDKName);
userSearch.set("userDeviceCodename", request.params.userDeviceCodename);
userSearch.set("userSearchedFor", request.params.userSearchedFor);
userSearch.set("userLocation", request.params.userLocation);


userSearch.save()
.then((userSearch) => {
	 // Execute any logic that should take place after the object is saved.
	 response.success('saved');
}, (error) => {
	 // Execute any logic that should take place if the save fails.
	 // error is a Parse.Error with an error code and message.
	response.error('error: ' + error.message);
});

}, { useMasterKey: true });

And my code for this...

HashMap<String, Object> params = new HashMap<String, Object>();
                    params.put("deviceManufacturer", deviceManufacturer);
                    params.put("deviceModel", deviceModel);
                    params.put("deviceRelease", deviceRelease);
                    params.put("deviceSDKName", deviceSDKName);
                    params.put("userDeviceCodename", deviceCodename);
                    params.put("userSearchedFor", itemDescription);
                    params.put("userLocation", userLocation);

                    ParseCloud.callFunctionInBackground("SaveSearchByDevice", params, new FunctionCallback< Map<String, Object> >() {
                        public void done(Map<String, Object> mapObject, ParseException e) {
                            if (e == null){
                                //saved
                            } else {
                                //print e.getmessage() = badjsonresponse
                            }
                        }
                    });

Thanks.

@mginz83 mginz83 changed the title bad json request issue, cant figure out why. bad json response issue, cant figure out why. Oct 10, 2018
@mginz83
Copy link
Author

mginz83 commented Oct 10, 2018

For the record this is the server url.
I have seen that the / at the end sometimes in the reason. in this case, its not.
https://app-name.herokuapp.com/parse/

@flovilmart
Copy link
Contributor

Your server code don’t make sense and isn’t valid javascript

@mginz83
Copy link
Author

mginz83 commented Oct 10, 2018

So the SaveSearchByDevice code was from the JS docs.
The other one was from another functions I used that was working.

@flovilmart
Copy link
Contributor

That’s the GetKeys function that is really not proper Js.

And when you say ‘from the JS DOCS’, can you share a link?

@mginz83
Copy link
Author

mginz83 commented Oct 11, 2018

Sorry I didnt find the getKeys on the parses docs. It was the other function, but I found a solutation on that.

I am still having issues with the getkeys, how would I send a success back to the app? I am return a string and split it, but I rather return a json object (map)

@flovilmart
Copy link
Contributor

Use stackoverflow please for such questions that refer to implementation details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants