我试图按照this教程来解析JSON
web service
以显示在应用程序中。PHP/MYSQL/JSON:调整api解析IOS应用程序
,此教程需要输入贷款从一种名为KIVA
如下:
{"loans":[{"id":961236,"name":"Alhassan","description":{"languages":["en"]},"status":"fundraising","funded_amount":0,"basket_amount":0,"image":{"id":1960690,"template_id":1},"activity":"Personal Purchases","sector":"Personal Use","themes":["Rural Exclusion"],"use":"to buy food and clothing, eliminating pressure to sell maize for low prices at harvest","location":{"country_code":"NG","country":"Nigeria","town":"Kaduna","geo":{"level":"town","pairs":"10 8","type":"point"}},"partner_id":288,"posted_date":"2015-10-13T21:00:03Z","planned_expiration_date":"2015-11-12T21:00:03Z","loan_amount":200,"borrower_count":1,"lender_count":0,"bonus_credit_eligibility":false,"tags":[]}
从我的服务输出的电流:
[{"userid":"1","shcom":"hello","lcom":"hello there friend"}]
我认为最主要的我的web服务相对于上面的缺失是:
“贷款”:`[在输出开始时。
所以我想我需要做的是插入在JSON
输出在应用中objective-c
代码的开头使用“贷款”来创建一个array
如下:
NSArray* latestLoans = [json objectForKey:@"loans"]; // gets JSON
NSLog(@"loans: %@", latestLoans); // Prints it
我会怎么需要做我的PHP代码来打印出JSON的教程?
感谢您的任何建议:
编辑:
PHP:
while($row = mysql_fetch_assoc($res)) {
$loans[] = $row;
}
请更新您的文章并添加生成'json'输出的'php'代码。通过你发布的内容,似乎你正在寻找一个名为_loans_的关键字,这个关键字在你的'json'中显然缺少。因此,在'php'文件中,您必须添加一个名为_loans_的“key”,并为您的输出(现在已包含在您的文章中)分配整个生成的字符串作为值。 – EhsanT