duanaoou4105 2016-04-23 11:51
浏览 66
已采纳

没有从在线服务器获得json响应

So I came over this tutorial right here https://www.youtube.com/watch?v=mdAXqQoADt8 (last part of it) everything is working absolutly fine when I'm refering to my local server.

Now I switched it up to an online server/database to test if it works the same way. Also here everything is working fine except of the json response in the onPostExecute Method. I'm getting no messages from registration or login anymore. I really can't figure out how to solve this problem and I don't understand why it doesn't work the same way when I switch it up to an online server/database.

Hope anyone here can help me with that. I'll post some code below, maybe somebody can figure it out without doing the whole tutorial.

Thankful for any help!

@Override
    protected void onPostExecute(String json) {

        try {
            Log.d("JSON-String",json+"");
            progressDialog.dismiss();
            JSONObject jsonObject = new JSONObject(json);
            JSONArray jsonArray = jsonObject.getJSONArray("server_response");
            JSONObject JO = jsonArray.getJSONObject(0);
            String code = JO.getString("code");
            String message = JO.getString("message");
            if (code.equals("reg_true"))
            {
                showDialog("Registrierung erfolgt.", message, code);
            }
            else if (code.equals("reg_false"))
            {
                showDialog("Registrierung fehlgeschlagen", message, code);
            }

            else if(code.equals("login_true"))
            {
                Intent intent = new Intent(activity, Talkscreen.class);                                        //SPÄTER WIEDER RAUSNEHMEN
                activity.startActivity(intent);
                activity.finish();
            }
            else if (code.equals("login_false"))
            {
                showDialog("Login fehlgeschlagen", message,code);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }


    }
  • 写回答

1条回答 默认 最新

  • duancu4731 2016-04-23 12:53
    关注

    It seems you're getting wrong JSON string from the server.

    2905-2905/com.appmac.ron.testapp W/System.err: org.json.JSONException: Value <h3>DB< of type java.lang.String cannot be converted to JSONObject
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at org.json.JSON.typeMismatch(JSON.java:111)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:160)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:173)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at com.appmac.ron.testapp.ServerKlassen.BackgroundTask.onPostExecute(BackgroundTask.java:172)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at com.appmac.ron.testapp.ServerKlassen.BackgroundTask.onPostExecute(BackgroundTask.java:39)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at android.os.AsyncTask.finish(AsyncTask.java:651)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at android.os.AsyncTask.-wrap1(AsyncTask.java)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:668)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at android.os.Looper.loop(Looper.java:148)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    04-23 12:35:53.172 2905-2905/com.appmac.ron.testapp W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    

    Above error shows that String could not be converted to JSON object.

    Check the server code for any bug.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题