gpt4 book ai didi

php - 安卓 JSON 不工作

转载 作者:行者123 更新时间:2023-11-30 04:15:30 26 4
gpt4 key购买 nike

我有以下代码,我想在 JSON.getJSONfromURL() 方法中传递额外的参数,但是当我检查 android 时它抛出这个异常

04-11 11:58:18.929: E/AndroidRuntime(566): FATAL EXCEPTION: main 04-11 11:58:18.929: E/AndroidRuntime(566): java.lang.RuntimeException: Unable to start activity ComponentInfo{cyclist.project/cyclist.project.user_discussion}: java.lang.NullPointerException 04-11 11:58:18.929: E/AndroidRuntime(566): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 04-11 11:58:18.929: E/AndroidRuntime(566): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 04-11 11:58:18.929: E/AndroidRuntime(566): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 04-11 11:58:18.929: E/AndroidRuntime(566): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 04-11 11:58:18.929: E/AndroidRuntime(566): at android.os.Handler.dispatchMessage(Handler.java:99) 04-11 11:58:18.929: E/AndroidRuntime(566): at android.os.Looper.loop(Looper.java:123) 04-11 11:58:18.929: E/AndroidRuntime(566): at android.app.ActivityThread.main(ActivityThread.java:4627) 04-11 11:58:18.929: E/AndroidRuntime(566): at java.lang.reflect.Method.invokeNative(Native Method) 04-11 11:58:18.929: E/AndroidRuntime(566): at java.lang.reflect.Method.invoke(Method.java:521) 04-11 11:58:18.929: E/AndroidRuntime(566): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 04-11 11:58:18.929: E/AndroidRuntime(566): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 04-11 11:58:18.929: E/AndroidRuntime(566): at dalvik.system.NativeStart.main(Native Method) 04-11 11:58:18.929: E/AndroidRuntime(566): Caused by: java.lang.NullPointerException 04-11 11:58:18.929: E/AndroidRuntime(566): at cyclist.project.JSON.getJSONfromURL(JSON.java:60) 04-11 11:58:18.929: E/AndroidRuntime(566): at cyclist.project.user_discussion.setList(user_discussion.java:250) 04-11 11:58:18.929: E/AndroidRuntime(566): at cyclist.project.user_discussion.onCreate(user_discussion.java:154) 04-11 11:58:18.929: E/AndroidRuntime(566): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 04-11 11:58:18.929: E/AndroidRuntime(566): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) 04-11 11:58:18.929: E/AndroidRuntime(566): ... 11 more

代码:

    JSONObject json;

try {
json = new JSONObject(
JSON.getJSONfromURL("http://myweb.com/ws_cyc/events_service.php?action=get_chats&title=fsfbnn" ));
JSONArray miles = json.getJSONArray("cyc");
JSONObject rec;
JSONObject rec2 = null;

for (int i=0; i<miles.length(); i++){
rec = miles.getJSONObject(i);
rec2 = rec.getJSONObject("cycObject");
new discussion_item(rec2.getString("Chats").toString());
ImgList.add( rec2.getString("image_path").toString() );
list.add( rec2.getString("email").toString() + ": " + rec2.getString("Chats").toString() );
}
} catch (JSONException e) {
e.printStackTrace();
}

请指导我如何在 JSON.getJSONfromURL() 中传递附加参数以及 php 将如何获取它,我的 php 代码是捕获 jason

$titlez = json_decode($_GET['title']);

最佳答案

最好使用Gson来获取JSON数据,速度快,效率高。

关于php - 安卓 JSON 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10101340/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com