iOS json解析器错误
<p><p>我正在尝试使用 json 从数据库中获取数据。该程序在我使用 json 解析器获取数据之前运行,但在我使用解析器时崩溃。有什么问题? json 和 peopleList 都是 NSMutableArray。您可以在此处找到 json 的缩短版本:</p>
<pre><code>{"persons":[{"id":3,"name":"Micke","userId":2,"expectations":"None","skills":"Many","description":"Yes I want to want","experience":"From everywhere","created_at":"2013-09-27T07:48:55.612Z","updated_at":"2013-09-27T07:48:55.612Z"}]}
</code></pre>
<p>这里的代码:</p>
<pre><code>{
NSURL *url = ;
NSData *data = [ initWithContentsOfURL:url];
json = ;
peopleList = [init];
for (int i =0; i<json.count; i++) {
NSString * pId = [objectForKey:@"id"];
NSString * pName = [objectForKey:@"name"];
NSString * pUserId = [objectForKey:@"userId"];
NSString * pExpectations = [objectForKey:@"expectations"];
NSString * pSkills = [objectForKey:@"skills"];
NSString * pDescription = [objectForKey:@"description"];
NSString * pExperience = [objectForKey:@"experience"];
NSString * pCreatedAt = [objectForKey:@"created_at"];
NSString * pUpdatedAt = [objectForKey:@"updated_at"];
Person *person = [
initWithID:pId andName:pName andUserId:pUserId andExpectations:pExpectations andSkills:pSkills andDescription:pDescription andExperience:pExperience andCreated_at:pCreatedAt andUpdated_at:pUpdatedAt];
;
}
}
</code></pre>
<p>错误开始于:</p>
<pre><code>2013-11-13 19:26:51.644 FENA -: unrecognized selector sent to instance 0x109088fc0
2013-11-13 19:26:51.651 FENA *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-: unrecognized selector sent to instance 0x109088fc0'
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>你有字典,所以试试这个</p>
<pre><code>NSString * pId = [[ objectAtIndex:i] objectForKey:@"id"];
...
</code></pre></p>
<p style="font-size: 20px;">关于iOS json解析器错误,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19952899/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19952899/
</a>
</p>
页:
[1]