2013-02-06 86 views
-2

我想從android源代碼發送下面的字符串到javascript回調函數。JavaScript回調函數不會以Android字符串的長字符串調用

{ 
    "DefaultScope.mytable": { 
     "name": "DefaultScope.mytable", 
     "rows": { 
      "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid'69cb1eed-6ea4-c29d-ea7a-a3b4b8cde5bf')": { 
       "ID": "69cb1eed-6ea4-c29d-ea7a-a3b4b8cde5bf", 
       "FirstName": "xxx", 
       "LastName": "x1x1", 
       "PhoneNumber": "999922223", 
       "EmailId": "[email protected]", 
       "__metadata": { 
        "uri": "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid'69cb1eed-6ea4-c29d-ea7a-a3b4b8cde5bf')", 
        "type": "DefaultScope.mytable" 
       } 
      }, 
      "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid'86159fca-1832-418a-0416-bb1e7555dd56')": { 
       "ID": "86159fca-1832-418a-0416-bb1e7555dd56", 
       "FirstName": "yyy", 
       "LastName": "R", 
       "PhoneNumber": "98789878", 
       "EmailId": "[email protected]", 
       "__metadata": { 
        "uri": "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid'86159fca-1832-418a-0416-bb1e7555dd56')", 
        "type": "DefaultScope.mytable" 
       } 
      }, 
      "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid'000047f6-c01b-8e95-6a13-c44c75ec4537')": { 
       "ID": "000047f6-c01b-8e95-6a13-c44c75ec4537", 
       "FirstName": "Sample", 
       "LastName": "Sample", 
       "PhoneNumber": "999999999", 
       "EmailId": "[email protected]", 
       "__metadata": { 
        "uri": "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid'000047f6-c01b-8e95-6a13-c44c75ec4537')", 
        "type": "DefaultScope.mytable" 
       } 
      }, 
      "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid'71d7b329-edd5-00dd-4579-eacfc6ebd129')": { 
       "ID": "71d7b329-edd5-00dd-4579-eacfc6ebd129", 
       "FirstName": "zzz", 
       "LastName": "M", 
       "PhoneNumber": "8787676733", 
       "EmailId": "[email protected]", 
       "__metadata": { 
        "uri": "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid'71d7b329-edd5-00dd-4579-eacfc6ebd129')", 
        "type": "DefaultScope.mytable" 
       } 
      }, 
      "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid'b6e23d7c-5f06-7c25-f0c7-f7a67ae874db')": { 
       "ID": "b6e23d7c-5f06-7c25-f0c7-f7a67ae874db", 
       "FirstName": "dddd", 
       "LastName": "r", 
       "PhoneNumber": "8009008767", 
       "EmailId": "[email protected]", 
       "__metadata": { 
        "uri": "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid'b6e23d7c-5f06-7c25-f0c7-f7a67ae874db')", 
        "type": "DefaultScope.mytable" 
       } 
      }, 
      "d3be059d-14d7-7f5a-e7ab-7cf9d4d08fcf": { 
       "__metadata": { 
        "type": "DefaultScope.mytable", 
        "tempId": "d3be059d-14d7-7f5a-e7ab-7cf9d4d08fcf", 
        "isDirty": true 
       }, 
       "ID": "d3be059d-14d7-7f5a-e7ab-7cf9d4d08fcf", 
       "FirstName": "bbb", 
       "LastName": "aaa", 
       "PhoneNumber": "9009877899", 
       "EmailId": "[email protected]" 
      } 
     } 
    } 
} 

我在我的Java文件加載此如下

webView.loadUrl("javascript:"+callBackName+"('" + mStatus + "', '" + mString+ "')"); 

回調:

var processor = (function() { 
     return { 
      onSuccess: function (data) { 
       alert("Success"); 
      }, 
      onFailure: function (error) { 
       alert("Error"); 
      } 
     }; 
    })(); 

此回調不叫。

注意:如果我通過 「」 在mString變量,然後的onSuccess 被稱爲

+0

你能告訴我爲什麼我會投票嗎? – Ponmalar

回答

0

我發現有上述值的錯誤。該字符串有更多的單引號,所以我無法加載Webview中的值。現在我已經通過「\'」替換了「\'」字符串。現在工作很好。

{ 
    "DefaultScope.mytable": { 
     "name": "DefaultScope.mytable", 
     "rows": { 
      "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid\’69cb1eed-6ea4-c29d-ea7a-a3b4b8cde5bf\’)": { 
       "ID": "69cb1eed-6ea4-c29d-ea7a-a3b4b8cde5bf", 
       "FirstName": "xxx", 
       "LastName": "x1x1", 
       "PhoneNumber": "999922223", 
       "EmailId": "[email protected]", 
       "__metadata": { 
        "uri": "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid\’69cb1eed-6ea4-c29d-ea7a-a3b4b8cde5bf\’)", 
        "type": "DefaultScope.mytable" 
       } 
      }, 
      "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid\’86159fca-1832-418a-0416-bb1e7555dd56\’)": { 
       "ID": "86159fca-1832-418a-0416-bb1e7555dd56", 
       "FirstName": "yyy", 
       "LastName": "R", 
       "PhoneNumber": "98789878", 
       "EmailId": "[email protected]", 
       "__metadata": { 
        "uri": "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid\’86159fca-1832-418a-0416-bb1e7555dd56\’)", 
        "type": "DefaultScope.mytable" 
       } 
      }, 
      "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid\’000047f6-c01b-8e95-6a13-c44c75ec4537\’)": { 
       "ID": "000047f6-c01b-8e95-6a13-c44c75ec4537", 
       "FirstName": "Sample", 
       "LastName": "Sample", 
       "PhoneNumber": "999999999", 
       "EmailId": "[email protected]", 
       "__metadata": { 
        "uri": "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid\’000047f6-c01b-8e95-6a13-c44c75ec4537\’)", 
        "type": "DefaultScope.mytable" 
       } 
      }, 
      "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid\’71d7b329-edd5-00dd-4579-eacfc6ebd129\’)": { 
       "ID": "71d7b329-edd5-00dd-4579-eacfc6ebd129", 
       "FirstName": "zzz", 
       "LastName": "M", 
       "PhoneNumber": "8787676733", 
       "EmailId": "[email protected]", 
       "__metadata": { 
        "uri": "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid\’71d7b329-edd5-00dd-4579-eacfc6ebd129\’)", 
        "type": "DefaultScope.mytable" 
       } 
      }, 
      "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid\’b6e23d7c-5f06-7c25-f0c7-f7a67ae874db\’)": { 
       "ID": "b6e23d7c-5f06-7c25-f0c7-f7a67ae874db", 
       "FirstName": "dddd", 
       "LastName": "r", 
       "PhoneNumber": "8009008767", 
       "EmailId": "[email protected]", 
       "__metadata": { 
        "uri": "http://www.xxx.com/demo/MyService/DefaultScopeSyncService.svc/mytable(ID=guid\’b6e23d7c-5f06-7c25-f0c7-f7a67ae874db\’)", 
        "type": "DefaultScope.mytable" 
       } 
      }, 
      "d3be059d-14d7-7f5a-e7ab-7cf9d4d08fcf": { 
       "__metadata": { 
        "type": "DefaultScope.mytable", 
        "tempId": "d3be059d-14d7-7f5a-e7ab-7cf9d4d08fcf", 
        "isDirty": true 
       }, 
       "ID": "d3be059d-14d7-7f5a-e7ab-7cf9d4d08fcf", 
       "FirstName": "bbb", 
       "LastName": "aaa", 
       "PhoneNumber": "9009877899", 
       "EmailId": "[email protected]" 
      } 
     } 
    } 
}