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 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看