2016-02-12 178 views
4

我正在使用此Parse Server Guide来创建解析服务器的本地实例。我下载和安装的例子,它运行完美,但是当我尝试使用Android SDK我得到这个错误解析服务器错误的json响应错误代码100

02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens 

W/System.err﹕ com.parse.ParseRequest$ParseRequestException: bad json response 
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at com.parse.ParseRequest.newTemporaryException(ParseRequest.java:290) 
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at com.parse.ParseRESTCommand.onResponseAsync(ParseRESTCommand.java:308) 
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at com.parse.ParseRequest$3.then(ParseRequest.java:137) 
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at com.parse.ParseRequest$3.then(ParseRequest.java:133) 
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task$15.run(Task.java:917) 
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105) 
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task.completeAfterTask(Task.java:908) 
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task.continueWithTask(Task.java:715) 
02-12 22:41:58.662 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task.continueWithTask(Task.java:726) 
02-12 22:41:58.674 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task$13.then(Task.java:818) 
02-12 22:41:58.674 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task$13.then(Task.java:806) 
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at bolts.Task$15.run(Task.java:917) 
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at java.lang.Thread.run(Thread.java:841) 
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ Caused by: org.json.JSONException: Value Cannot of type java.lang.String cannot be converted to JSONObject 
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at org.json.JSON.typeMismatch(JSON.java:111) 
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at org.json.JSONObject.<init>(JSONObject.java:159) 
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at org.json.JSONObject.<init>(JSONObject.java:172) 
02-12 22:41:58.682 7211-7211/com.christoandrew.android.authens W/System.err﹕ at com.parse.ParseRESTCommand.onResponseAsync(ParseRESTCommand.java:298) 
02-12 22:41:58.690 7211-7211/com.christoandrew.android.authens W/System.err﹕ ... 13 more 

这里是我的index.js

// Example express application adding the parse-server module to expose Parse 
// compatible API routes. 

var express = require('express'); 
var ParseServer = require('parse-server').ParseServer; 

var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI 

if (!databaseUri) { 
    console.log('DATABASE_URI not specified, falling back to localhost.'); 
} 

var api = new ParseServer({ 
    databaseURI: databaseUri || 'mongodb://localhost:27017/authens', 
    cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js', 
    appId: process.env.APP_ID || 'UBXrCTUXuXf6fEBpbE7sHBamq4b0RdQcASFTHxo9', 
    masterKey: process.env.MASTER_KEY || 'ghFiFWGtdymY3oXqWDTDBz6RyW7XdMyWzjXoJjFb', //Add your master key here. Keep it secret! 
    clientKey: '4m2WpkkGCX77w3FNq3JWT74nVgRKNsgTj10Q1s4t', 
    //restAPIKey: 'b7gUiB4cI7JeKLqKCWCkTZbBX4YA9S7xlQuwmUqX', 
    //javascriptKey: '0qBhikhxV8ZtM95o1zTLFhhiuuLGiwDVcTxyvNdw', 
// dotNetKey: 'rc0uYDFU3Bo5U24PlBxKMBX7GpsHj8QHJLLVgsFg', 
}); 
// Client-keys like the javascript key or the .NET key are not necessary with parse-server 
// If you wish you require them, you can set them as options in the initialization above: 
// javascriptKey, restAPIKey, dotNetKey, clientKey 

var app = express(); 

// Serve the Parse API on the /parse URL prefix 
var mountPath = process.env.PARSE_MOUNT || '/parse'; 
app.use(mountPath, api); 

// Parse Server plays nicely with the rest of your web routes 
app.get('/', function(req, res) { 
    res.status(200).send('I dream of being a web site.'); 
}); 

var port = process.env.PORT || 1337; 
app.listen(port, function() { 
    console.log('parse-server-example running on port ' + port + '.'); 
}); 

我这是怎么初始化

Parse.enableLocalDatastore(this); 
    Parse.initialize(new Parse.Configuration.Builder(this) 
      .applicationId(getString(R.string.parse_app_id)) 
      .clientKey(getString(R.string.parse_client_key)) 
      .server("http://10.0.3.2:1337/parse") 
      .build()); 
    Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE); 

在教程中。我使用genymotion作为运行在10.0.3.2的虚拟设备。有什么我失踪或这是一个普遍问题。

更新

如果我从CMD卷曲用完美的作品

curl -X POST -H "X-Parse-Application-Id: UBXrCTUXuXf6fEBpbE7sHBamq4b0RdQcASFTHxo9" -H "X-Parse-Client-Key: 4m2WpkkGCX77w3FNq3JWT74nVgRKNsgTj10Q1s4t" -H "Content-Type: application/json" -d @json.txt http://localhost:1337/parse/classes/GameScore 
+0

我遇到了同样的问题。你找到解决方案吗? –

+0

尚未尝试 – christoandrew

回答

0

下载最新版本的的NodeJS并添加 “/” 像这样 “主机:端口/分析/”。这解决了我的问题。

6

我找到了解决方案。 取而代之的是

.server("http://10.0.3.2:1337/parse") 

使用本

.server("http://10.0.3.2:1337/parse/") 
+0

多数民众赞成我所做的太检查我的答案 – christoandrew

+0

为了明确,确保有一个尾随'/'您的服务器URL。愚蠢的错误,谢谢你指出。 – zgc7009

+0

哇谢谢。我从来不会发现这一点,因为它在服务器上没有斜线 – Muz