如何从PHP的jsonarray数组中获取数据?

时间:2015-08-12 19:04:02

标签: android arrays json

这是我从服务器脚本获得的输出:

{"task_id":"1","task_create_time":"2015-08-09 22:48:25","task_end_time":"0000-00-00 ``00:00:00","service_id":"2","task_status":"1","user_id":"1","user_email":"r@gmail.com","user_name":"rr","user_mobile":"1234567890"}{"task_id":"3","task_create_time":"2015-08-13 00:23:54","task_end_time":"0000-00-00 00:00:00","service_id":"2","task_status":"1","user_id":"2","user_email":null,"user_name":null,"user_mobile":null}

我想将此输出转换为Android中的自定义列表,但我收到很多错误。我的代码:

try {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url_jobdetail);
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    is = entity.getContent();

    // Toast.makeText(getApplicationContext(), “pass”,
    // Toast.LENGTH_SHORT).show();
} catch (Exception e) {

}
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
    sb.append(line + "\n");         
}
is.close();

result = sb.toString();

这是我得到的错误

08-13 12:42:34.935: I/InputMethodManager(23564): handleMessage: MSG_SET_ACTIVE true, was false

08-13 12:42:39.463:D / AbsListView(23564):checkAbsListViewlLogProperty得到无效命令 08-13 12:42:39.478:D / AndroidRuntime(23564):关闭VM 08-13 12:42:39.478:W / dalvikvm(23564):threadid = 1:线程退出未捕获异常(组= 0x40cb49c0) 08-13 12:42:39.499:E / AndroidRuntime(23564):致命异常:主要 08-13 12:42:39.499:E / AndroidRuntime(23564):java.lang.RuntimeException:无法启动活动ComponentInfo {com.OnDeOS.ondeos_internal / com.OnDeOS.ondeos_internal.jobs}:java.lang.NullPointerException 08-13 12:42:39.499:E / AndroidRuntime(23564):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343) 08-13 12:42:39.499:E / AndroidRuntime(23564):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395) 08-13 12:42:39.499:E / AndroidRuntime(23564):在android.app.ActivityThread.access $ 600(ActivityThread.java:162) 08-13 12:42:39.499:E / AndroidRuntime(23564):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1364) 08-13 12:42:39.499:E / AndroidRuntime(23564):在android.os.Handler.dispatchMessage(Handler.java:107) 08-13 12:42:39.499:E / AndroidRuntime(23564):在android.os.Looper.loop(Looper.java:194) 08-13 12:42:39.499:E / AndroidRuntime(23564):在android.app.ActivityThread.main(ActivityThread.java:5371) 08-13 12:42:39.499:E / AndroidRuntime(23564):at java.lang.reflect.Method.invokeNative(Native Method) 08-13 12:42:39.499:E / AndroidRuntime(23564):at java.lang.reflect.Method.invoke(Method.java:525) 08-13 12:42:39.499:E / AndroidRuntime(23564):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:833) 08-13 12:42:39.499:E / AndroidRuntime(23564):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600) 08-13 12:42:39.499:E / AndroidRuntime(23564):at dalvik.system.NativeStart.main(Native Method) 08-13 12:42:39.499:E / AndroidRuntime(23564):引起:java.lang.NullPointerException 08-13 12:42:39.499:E / AndroidRuntime(23564):at com.OnDeOS.ondeos_internal.jobs.onCreate(jobs.java:67) 08-13 12:42:39.499:E / AndroidRuntime(23564):在android.app.Activity.performCreate(Activity.java:5122) 08-13 12:42:39.499:E / AndroidRuntime(23564):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081) 08-13 12:42:39.499:E / AndroidRuntime(23564):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307) 08-13 12:42:39.499:E / AndroidRuntime(23564):... 11更多

1 个答案:

答案 0 :(得分:-1)

您是否能够在“结果”变量中获得响应?如果是这样,你可以像这样解析它:

declare -x workspace_root_path="$workspaceProjPath"
export workspace_path="$workspaceProjPathLocal"