我正在尝试从解析云中检索JsonArray到android,到目前为止我已经设法将JsonArray从android发送到云端:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
HashMap<String, Object> params = new HashMap<String, Object>();
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
try {
jsonObject.put("name", "first name");
jsonObject.put("number", "111");
jsonArray.put(jsonObject);
JSONObject mainObj = new JSONObject();
mainObj.put("contacts", jsonArray);
params.put("all", mainObj);
System.out.println(mainObj);
System.out.println("-----------------------");
System.out.println(jsonArray);
System.out.println("-----------------------");
System.out.println(params);
ParseCloud.callFunctionInBackground("test", params, new FunctionCallback<HashMap<String, Object>>() {
@Override
public void done(HashMap<String, Object> object, ParseException e) {
System.out.println(object);
System.out.println(object.get("all").toString());
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
服务器部分是这样的:
Parse.Cloud.define("test", function(request, response) {
response.success(request.params);
});
但是当我打印时,我一直得到null而不是对象和nullPointerException:System.out.println(object.get("all").toString());
01-10 20:46:27.526 28762-28762 / com.example.swampsoftware.blbmonitor I / System.out: {“employees”:[{“number”:“111”,“name”:“名字“}]} 01-10 20:46:27.526 28762-28762 / com.example.swampsoftware.blbmonitor I / System.out:------------------- 01-10 20:46:27.526 28762-28762 / com.example.swampsoftware.blbmonitor I / System.out:[ {“number”:“111”,“name”:“first name”}] 01-10 20:46:27.526 28762-28762 / com.example.swampsoftware.blbmonitor I / System.out:------------------- 01-10 20:46:27.526 28762-28762 / com.example.swampsoftware.blbmonitor I / System.out: {movie = The Matrix,all = {“employees”:[{“number”:“111”,“name “:“名字”}]}} 01-10 20:46:27.576 28762-28762 / com.example.swampsoftware.blbmonitor I / System.out:=========== null 01-10 20:46:27.576 28762-28762 / com.example.swampsoftware.blbmonitor D / AndroidRuntime:关闭VM 01-10 20:46:27.576 28762-28762 / com.example.swampsoftware.blbmonitor W / dalvikvm:threadid = 1:线程退出时未捕获异常(group = 0x40f8d300) 01-10 20:46:27.576 28762-28762 / com.example.swampsoftware.blbmonitor E / AndroidRuntime:FATAL EXCEPTION:main 显示java.lang.NullPointerException 在com.example.swampsoftware.blbmonitor.MainActivity $ 1.done(MainActivity.java:117) 在com.example.swampsoftware.blbmonitor.MainActivity $ 1.done(MainActivity.java:113) 在com.parse.ParseTaskUtils $ 2 $ 1.run(ParseTaskUtils.java:115) 在android.os.Handler.handleCallback(Handler.java:615) 在android.os.Handler.dispatchMessage(Handler.java:92) 在android.os.Looper.loop(Looper.java:137) 在android.app.ActivityThread.main(ActivityThread.java:4898) at java.lang.reflect.Method.invokeNative(Native Method) 在java.lang.reflect.Method.invoke(Method.java:511) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1006) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 在dalvik.system.NativeStart.main(本地方法)
谢谢。