“JSONValue failed” Error while fetching data from server into iPhone

℡╲_俬逩灬. 提交于 2020-01-06 03:33:06

问题


I am fetching data from server into my iPhone app.

For fetching data from server, I am using HTTP Post method and for parsing data obtained I am using SBJSON Parser.

When the first time my app launches, the data is not fetched.

It shows the following failure log in Console. The app does not crash but just that data is not fetched.

<html>Your request timed out.  
Please retry the request.                                                                                                 </html>
2011-04-21 08:39:06.339 Hive[1594:207] -JSONValue failed. Error trace is: (
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\"   UserInfo=0x4cabe90 {NSLocalizedDescription=Unrecognised leading character}"
)

The app fetches data properly from the second time onwards. It only gives this error when the app runs the first time.

What could be wrong?


回答1:


Without analysis of the server and its resources it is difficult to determine why the server is taking too long to respond.

One thing to think about is how much time occurs between the last time you make the JSON attempt and the next time you make your "first attempt". Maybe then see if you an recreate it using a web browser.

Is the server a production quality server? If not, it may be "spinning up" to answer the first request which takes too long for the first response.

Personally, I wrote a generic JSON feed class that has a failure retry option. If it receives nothing or invalid JSON, it will retry x times at y seconds intervals based on what you pass it. It takes a little more work initially but it will payoff for two reasons.

1) It can be reused over and over and an update, like using ASIHTTRequest like Terente's good suggestion can be made in a single file.

2) While you may not expect a response to fail, server slowness or network issues can occur causing a flawed response.




回答2:


You could use ASIHTTRequest and if you get an time out try to make an new request to the server.



来源:https://stackoverflow.com/questions/5739878/jsonvalue-failed-error-while-fetching-data-from-server-into-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!