开发者

parse json with a callback function in android

I am firing a request through my android application using HttpPost , as the request is returning a JSON Callback function , i don't know how to handle it and parse it.

returned format:

handleEmployeeResponse({
  "records": [
    {
      "fullDesc": "Records for employe",
      "id": "Emp_1",
      "name": "Jack"
    }
  ]
});

in a 开发者_运维百科firebug i can see as a response text

handleEmployeeResponse({"records":[{"fullDesc":"Records for employe","id":"Emp_1","name":"Jack"}]});

if i will parse the above response using JSONObject jObject = new JSONObject(jString); i am surely gonna get JSON parsing error as the above response is not valid json at all so i have to remove "handleEmployeeResponse , ( , ); " form the response string then i need to pass it so JSONObject can anyone tell me how to parse json with a callback function in android


It looks like your service is returning a response in the JSONP format (JSON with Padding). You either need to regex out the JSON message, or find out a way to ask the service not to return the padding.


Have a look here : you should use the JSONTokener Class and thus get a JSONObject corresponding to your structure.

TOKENER

the example is pretty self-explanatory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜