Parse의 REST API를 오랫동안 사용해 왔지만 이제는 Parse 서버에 대한 요청을 줄이기 위해 Cloud 코드 기능을 탐색하기 시작했습니다. 꽤 좋은 - 내가 지금까지 읽었던 것을 근거로한다. Parse의 서버에서 비즈니스 로직을 정의하고 실행한다는 사실은 매우 강력한 도구처럼 보입니다.Parse 클라우드 함수를 호출 할 때 json 응답이 잘못됨
그러나 기본 사항까지 제대로 수행 할 수 없었습니다. 나는이 Getting Started Guide을 따라 갔지만 백그라운드에서 "hello"함수를 호출하려고 할 때 막혔다. 여기에 내가 무슨 짓을했는지의 :
- 안드로이드 Studio 프로젝트에 jar 파일을 가져온
- 구문 분석의 PowerShell 명령 도구 로컬 클라우드 코드 디렉토리를 작성
- 설치합니다. 기본적으로는
- 실행 호출이
hello
기능에 의해 내 안드로이드 응용 프로그램에서 테스트 배포 "main.js" - 을에서
hello
함수를 만듭니다하지만 응답 여기
을 구문 분석하는 데 실패 스택 트레이스의 오류 : 이것은 내가 전화 한 클라우드 코드 기능입니다
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)
...
Parse.Cloud.define("hello", function(request, response) {
response.success("Hello world!");
});
내가 안드로이드에 대한 구문 분석 SDK를 사용하여 함수를 호출을 만들고있어 어떻게이는 ...
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);
}
}
});
ctx
변수는 그냥 도우미의은 "컨텍스트"클래스의 인스턴스와 Utils
입니다 LogCat에 사용 정보를 인쇄하기 위해 디버깅이 켜져있을 때 사용하는 클래스입니다.
오래된 포럼 사이트 나 헌신적 인 Google 그룹스에서는 많은 정보를 찾을 수 없었습니다. 어떤 도움을 받기 전에이 문제가 발생했을 경우
'Hello World!'대신 json 형식으로 데이터를 반환 해 보셨습니까? 내 첫번째 추측은 그것이 json을 파싱하려고 시도하고 실패한다는 것입니다. – chris
json 응답을 게시 할 수 있습니까? 의견을 주신 덕분에 @chris –
. 그래, 그건 내 첫 번째 추측이었다. 나는 평범한 json 객체와 "문자열 화 된"json 객체를 모두 response.success 함수에 전달하려고 시도했다. 또한 콜백의 제네릭 형식을 String에서 Java 코드의 JSONObject로 변경할 것을 시도했습니다. 'O' 매개 변수는 항상 'null'이됩니다 – Leo