gpt4 book ai didi

PHP/MYSQL/JSON : Tweak api for parsing in IOS app

转载 作者:行者123 更新时间:2023-11-29 21:56:29 25 4
gpt4 key购买 nike

我正在尝试关注this解析 JSON web 服务 以在应用程序中显示的教程。

本教程从名为 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"}]

相对于上述服务,我认为我的网络服务缺少的主要内容是:

"loans":`[ 在输出的开头。

所以我认为我需要做的是将其插入到 JSON 输出的开头,因为应用程序中的 objective-c 代码使用“loans”来创建一个数组如下:

  NSArray* latestLoans = [json objectForKey:@"loans"]; // gets JSON

NSLog(@"loans: %@", latestLoans); // Prints it

我需要对 PHP 代码执行什么操作才能按照教程中的方式打印出 JSON?

感谢您的建议:

编辑:

PHP:

while($row = mysql_fetch_assoc($res)) {
$loans[] = $row;
}

最佳答案

这里的答案是改变

$loans[] = array('$loan);
to:

$loans[] = array('loans'=>$loan);

这会在开头插入“贷款”

关于PHP/MYSQL/JSON : Tweak api for parsing in IOS app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33112864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com