开发者

parse json with a callback function in android

开发者 https://www.devze.com 2023-03-22 12:20 出处:网络
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.

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

精彩评论

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

关注公众号