【发布时间】:2015-05-08 16:53:15
【问题描述】:
我知道很多问题都解决了这个问题,但我没有找到对我有帮助的问题...
当我解析从本地主机(MAMP 服务器)下载的 json 数据时,我遇到 json 错误 3840,说明字符 0 周围的值无效...
我不明白为什么,因为我的数组上带有 var_dump 的 php 脚本显示(数组数组):
array(2) { [0]=> array(5) { ["ID"]=> string(1) "1" ["EDS"]=> string(4) "1000" ["lastname"]=> string(8) "My lastname" ["firstname"]=> string(9) "My firstname" ["dateOfBirth"]=> string(10) "19.12.1975" } [1]=> array(5) { ["ID"]=> string(1) "2" ["EDS"]=> string(4) "1001" ["lastname"]=> string(14) "Smith" ["firstname"]=> string(6) "John" ["dateOfBirth"]=> string(10) "11.11.1111" } }
...对我来说这似乎是一个有效的 json 数组。
当我记录下载的 NSMutableData 时,它不为空,而是类似于
76353648 2734b0a9 (+ around fifty like this).
我不知道是不是因为数据不完整,但我不知道我该如何继续进一步分析到底出了什么问题。
如果有人知道会发生什么(我知道这与无法识别的特殊字符有关),那就太好了。
非常感谢!
编辑:在原始问题中添加了后续代码:
在
(void)connectionDidFinishLoading:(NSURLConnection *)connection {
id jsonObject = [NSJSONSerialization JSONObjectWithData:_downloadedData options:NSJSONReadingAllowFragments error:&error];
if ([jsonObject isKindOfClass:[NSArray class]]) {
NSArray *deserializedArray = (NSArray *)jsonObject;
for (NSDictionary *jsonElement in deserializedArray)
{
Person *newPersonElement = [[PersonStore sharedStore] createPerson]; // --> what makes the app crash. But this method is working everywhere else...
// more code omitted
}
我不知道为什么这个初始化在这里崩溃...
【问题讨论】:
-
也许this 的回答会对你有所帮助。
-
从浏览器调用 api 会返回什么?并添加您的 php 代码。