0

我正在尝试将我的 android 应用程序连接到 localhost 并以 JSON 字符串的形式获取数据。成功获取 JSON 数据的 url http://mysite.dev/controller/read/format/json返回:

{
    "success": 1,
    "products": [
        {
            "annonce_id": 462,
            "accountType": "Particulier"                
        }
    ]
}

安卓代码:

// Building parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();

try {

   // getting JSON string from URL
   JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);              
   Log.d("Status", json.toString());

} catch (Exception e) {
    Log.e("JSON Parser", e.toString());
}

来自控制台的错误消息: 在此处输入图像描述

根据来自控制台的错误消息,我一直想知道HTML是从哪里来的。有没有办法在控制台中查看服务器在解析 JSON 之前返回的实际字符串?这将帮助我准确了解返回的内容。

注意:我是 Android 的新手,只需遵循本教程:http ://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/ 谢谢

4

2 回答 2

0

@Sharj 抱歉,我无法发表评论,因为我从服务器得到的响应很长。出于某种原因,由于我的应用程序正在连接到我的本地主机,它无法将域识别为有效域。我已经在网上上传了所有内容。谢谢。

07-11 18:41:45.233: I/global(26861): Loaded time zone names for en_US in 14773ms.
07-11 18:41:45.343: W/ResponseProcessCookies(26861): Cookie rejected: "BasicClientCookie[version=0,name=OUS,domain=.opendns.com,path=/,expiry=Thu Jan 01 00:00:01 GMT+00:00 1970]". Illegal domain attribute "opendns.com". Domain of origin: "www.website-unavailable.com"
07-11 18:41:46.063: D/json(26861): <html>
07-11 18:41:46.063: D/json(26861):     <head>
07-11 18:41:46.063: D/json(26861):         <title>  </title>
07-11 18:41:46.063: D/json(26861):         <script type="text/javascript">
07-11 18:41:46.063: D/json(26861):             function bredir(a, b, c, d, e, ldr, ifc) {
07-11 18:41:46.063: D/json(26861):                 var h, i, j;
07-11 18:41:46.063: D/json(26861):                 var f = 0;
07-11 18:41:46.063: D/json(26861):                 var g = 0;
07-11 18:41:46.063: D/json(26861):                 var k = false;
07-11 18:41:46.063: D/json(26861):                 var l = false;
07-11 18:41:46.063: D/json(26861):                 var m = [
07-11 18:41:46.063: D/json(26861):                     [300, 250, false],
07-11 18:41:46.063: D/json(26861):                     [250, 250, false],
07-11 18:41:46.063: D/json(26861):                     [240, 400, false],
07-11 18:41:46.063: D/json(26861):                     [336, 280, false],
07-11 18:41:46.063: D/json(26861):                     [180, 150, false],
07-11 18:41:46.063: D/json(26861):                     [468, 60, false],
07-11 18:41:46.063: D/json(26861):                     [234, 60, false],
07-11 18:41:46.063: D/json(26861):                     [88, 31, false],
07-11 18:41:46.063: D/json(26861):                     [120, 90, false],
07-11 18:41:46.063: D/json(26861):                     [120, 60, false],
07-11 18:41:46.063: D/json(26861):                     [120, 240, false],
07-11 18:41:46.063: D/json(26861):                     [125, 125, false],
07-11 18:41:46.063: D/json(26861):                     [728, 90, false],
07-11 18:41:46.063: D/json(26861):                     [160, 600, false],
07-11 18:41:46.063: D/json(26861):                     [120, 600, false],
07-11 18:41:46.063: D/json(26861):                     [300, 600, false],
07-11 18:41:46.063: D/json(26861):                     [300, 125, false],
07-11 18:41:46.063: D/json(26861):                     [530, 300, false],
07-11 18:41:46.063: D/json(26861):                     [190, 200, false],
07-11 18:41:46.063: D/json(26861):                     [470, 250, false],
07-11 18:41:46.063: D/json(26861):                     [720, 300, true],
07-11 18:41:46.063: D/json(26861):                     [500, 350, true],
07-11 18:41:46.063: D/json(26861):                     [550, 480, true],
07-11 18:41:46.063: D/json(26861):                     //YouTube:
07-11 18:41:46.063: D/json(26861):                     [560, 315, true],
07-11 18:41:46.063: D/json(26861):                     [640, 360, true],
07-11 18:41:46.063: D/json(26861):                     [853, 480, true],
07-11 18:41:46.063: D/json(26861):                     [1280, 720, true],
07-11 18:41:46.063: D/json(26861):                     //Vimeo:
07-11 18:41:46.063: D/json(26861):                     [400, 300, true],
07-11 18:41:46.063: D/json(26861):                     [500, 281, true],
07-11 18:41:46.063: D/json(26861):                     //Hulu:
07-11 18:41:46.063: D/json(26861):                     [480, 270, true],
07-11 18:41:46.063: D/json(26861):                     [512, 288, true],
07-11 18:41:46.063: D/json(26861):                     //metacafe:
07-11 18:41:46.063: D/json(26861):                     [440, 248, true],
07-11 18:41:46.063: D/json(26861):                     [460, 284, true],
07-11 18:41:46.063: D/json(26861):                     [540, 304, true],
07-11 18:41:46.063: D/json(26861):                     [600, 338, true],
07-11 18:41:46.063: D/json(26861):                     //Other dimensions (metacafe, myspace video, yahoo video, break.com, ustream, vevo, justin.tv, etc):
07-11 18:41:46.063: D/json(26861):                     [210, 120, true],
07-11 18:41:46.063: D/json(26861):                     [400, 300, true],
07-11 18:41:46.063: D/json(26861):                     [425, 350, true],
07-11 18:41:46.063: D/json(26861):                     [425, 360, true],
07-11 18:41:46.063: D/json(26861):                     [435, 251, true],
07-11 18:41:46.063: D/json(26861):                     [435, 271, true],
07-11 18:41:46.063: D/json(26861):                     [500, 300, true],
07-11 18:41:46.063: D/json(26861):                     [525, 295, true],
07-11 18:41:46.063: D/json(26861):                     [575, 324, true],
07-11 18:41:46.063: D/json(26861):                     [620, 389, true],
07-11 18:41:46.063: D/json(26861):                     [624, 351, true],
07-11 18:41:46.063: D/json(26861):                     [630, 381, true],
07-11 18:41:46.063: D/json(26861):                     [640, 385, true],
07-11 18:41:46.063: D/json(26861):                     [650, 368, true],
07-11 18:41:46.063: D/json(26861):                     [1000, 562, true],
07-11 18:41:46.063: D/json(26861):                     [1000, 563, true],
07-11 18:41:46.063: D/json(26861):                     [1000, 564, true]
07-11 18:41:46.063: D/json(26861):                 ];
07-11 18:41:46.063: D/json(26861):                 if (typeof window.innerHeight == "number") {
07-11 18:41:46.063: D/json(26861):                     g = window.innerHeight;
07-11 18:41:46.063: D/json(26861):                     f = window.innerWidth;
07-11 18:41:46.063: D/json(26861):                 } else if (typeof document.body.offsetHeight == "number") {
07-11 18:41:46.063: D/json(26861):                     g = document.body.offsetHeight;
07-11 18:41:46.063: D/json(26861):                     f = document.body.offsetWidth;
07-11 18:41:46.063: D/json(26861):                 }
07-11 18:41:46.063: D/json(26861):                 for (var n = 0; n < m.length; n++) {
07-11 18:41:46.063: D/json(26861):                     j = m[n];
07-11 18:41:46.063: D/json(26861):                     h = Math.abs(f - j[0]);
07-11 18:41:46.063: D/json(26861):                     i = Math.abs(g - j[1]);
07-11 18:41:46.063: D/json(26861):                     if (top != self) {
07-11 18:41:46.063: D/json(26861):                         ifc = 1;
07-11 18:41:46.063: D/json(26861):                     } else {
07-11 18:41:46.063: D/json(26861):                         ifc = 0;
07-11 18:41:46.063: D/json(26861):                     };
07-11 18:41:46.063: D/json(26861):                     if (h <= 2 && i <= 2) {
07-11 18:41:46.063: D/json(26861):                         k = true;
07-11 18:41:46.063: D/json(26861):                         l = j[2]
07-11 18:41:46.063: D/json(26861):                     }
07-11 18:41:46.063: D/json(26861):                 }
07-11 18:41:46.063: D/json(26861):                 if(f === 0 && g === 0){
07-11 18:41:46.063: D/json(26861):                     return;
07-11 18:41:46.063: D/json(26861):                 }
07-11 18:41:46.063: D/json(26861):                 if ((a != "www.facebook.com" && a != "platform.twitter.com") && (k || f < 100 && f !== 0 || g < 100 && g !== 0)) {
07-11 18:41:46.063: D/json(26861):                     if (l && self == parent) {
07-11 18:41:46.063: D/json(26861):                         return;
07-11 18:41:46.063: D/json(26861):                     }
07-11 18:41:46.063: D/json(26861):                     return "/b" + "anner.php?w=" + f + "&h=" + g + "&d=" + a + "&url=" + b + "&ref=" + c + "&view=" + d
07-11 18:41:46.063: D/json(26861):                 } else if ((a == "www.facebook.com" || a == "platform.twitter.com") && (f >= 250 && g >= 60) && (k || f < 100 && f !== 0 || g < 100 && g !== 0)) {
07-11 18:41:46.063: D/json(26861):                     if (l && self == parent) {
07-11 18:41:46.063: D/json(26861):                         return;
07-11 18:41:46.063: D/json(26861):  
于 2013-09-10T01:44:20.843 回答
0

在您的代码中查找函数 makeHttpRequest。在那里寻找您实际从服务器获得响应的行,然后在 Log.d 解析它之前在控制台中打印日志。

于 2013-09-10T01:17:43.777 回答