gpt4 book ai didi

objective-c - JSON Objective-c - 对象和数组的组合

转载 作者:搜寻专家 更新时间:2023-10-30 20:08:43 27 4
gpt4 key购买 nike

我的 JSON 网址是 http://api.kivaws.org/v1/loans/search.json?status=fundraising

我的目标代码使用以下代码显示 page_size : 20

NSData *allCourseData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising"]];



NSError *error;
NSMutableDictionary *JsonObject = [NSJSONSerialization
JSONObjectWithData:allCourseData options:NSJSONReadingMutableContainers
error:&error];
//NSLog(@"json object is: - %@", JsonObject);
//Print Page size
NSLog(@"Page size is %@", [[JsonObject objectForKey:@"paging"] objectForKey:@"page_size"]);

我的问题是如何循环到 Loans 数组以显示以下内容例如,它将显示名称、显示所有语言、状态,因此输出看起来像
============================
名称:“玛丽亚·路易莎”
语言:es,en
状态:“筹款”
部门:“零售”
位置

国家代码:“NI”


名称:“佛罗伦萨”语言:en
状态:“筹款”
部门:“零售”
地点
国家代码:“KE”

enter image description here

MyJSON 提要

{
"paging": {
"page": 1,
"total": 7279,
"page_size": 20,
"pages": 364
},
"loans": [
{
"id": 941933,
"name": "Maria Luisa",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969857,
"template_id": 1
},
"activity": "General Store",
"sector": "Retail",
"use": "to buy rice, chicken, sausages, corn, beans, and sugar.",
"location": {
"country_code": "NI",
"country": "Nicaragua",
"town": "Esteli",
"geo": {
"level": "town",
"pairs": "13.166667 -86.333333",
"type": "point"
}
},
"partner_id": 176,
"posted_date": "2015-09-04T09:20:02Z",
"planned_expiration_date": "2015-10-04T09:20:02Z",
"loan_amount": 600,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942181,
"name": "Florence",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970181,
"template_id": 1
},
"activity": "Retail",
"sector": "Retail",
"use": "to buy more stocks of maize.",
"location": {
"country_code": "KE",
"country": "Kenya",
"town": "Bondo",
"geo": {
"level": "town",
"pairs": "1 38",
"type": "point"
}
},
"partner_id": 138,
"posted_date": "2015-09-04T09:10:08Z",
"planned_expiration_date": "2015-10-04T09:10:08Z",
"loan_amount": 200,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942146,
"name": "Naziha",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970129,
"template_id": 1
},
"activity": "Fruits & Vegetables",
"sector": "Food",
"use": "to increase her merchandise and diversify the products in her shop.",
"location": {
"country_code": "LB",
"country": "Lebanon",
"town": "Ain Al Helwi",
"geo": {
"level": "town",
"pairs": "33.833333 35.833333",
"type": "point"
}
},
"partner_id": 77,
"posted_date": "2015-09-04T09:10:02Z",
"planned_expiration_date": "2015-10-04T09:10:02Z",
"loan_amount": 2500,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942180,
"name": "Sokean's Group",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970180,
"template_id": 1
},
"activity": "Home Appliances",
"sector": "Personal Use",
"themes": [
"Water and Sanitation"
],
"use": "to buy a water filter to provide safe drinking water for her family.",
"location": {
"country_code": "KH",
"country": "Cambodia",
"town": "Kandal",
"geo": {
"level": "town",
"pairs": "13 105",
"type": "point"
}
},
"partner_id": 311,
"posted_date": "2015-09-04T09:00:05Z",
"planned_expiration_date": "2015-10-04T09:00:05Z",
"loan_amount": 100,
"borrower_count": 2,
"lender_count": 0,
"bonus_credit_eligibility": false,
"tags": [
{
"name": "volunteer_like"
}
]
},
{
"id": 941931,
"name": "Lucia Ingrid",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969852,
"template_id": 1
},
"activity": "Personal Housing Expenses",
"sector": "Housing",
"themes": [
"Conflict Zones"
],
"use": "to invest in: electric wires, a fuse box, sockets, and labor to install electricity in her home.",
"location": {
"country_code": "SV",
"country": "El Salvador",
"geo": {
"level": "country",
"pairs": "13.833333 -88.916667",
"type": "point"
}
},
"partner_id": 81,
"posted_date": "2015-09-04T09:00:03Z",
"planned_expiration_date": "2015-10-04T09:00:03Z",
"loan_amount": 500,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 941930,
"name": "La Manzanita Group",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969849,
"template_id": 1
},
"activity": "Fruits & Vegetables",
"sector": "Food",
"use": "to invest in buying papayas and nance berries in bulk.",
"location": {
"country_code": "NI",
"country": "Nicaragua",
"town": "Masaya",
"geo": {
"level": "town",
"pairs": "11.966667 -86.1",
"type": "point"
}
},
"partner_id": 120,
"posted_date": "2015-09-04T08:50:02Z",
"planned_expiration_date": "2015-10-04T08:50:02Z",
"loan_amount": 450,
"borrower_count": 3,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 941926,
"name": "Manuel",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969843,
"template_id": 1
},
"activity": "Property",
"sector": "Housing",
"use": "to buy two acres of land.",
"location": {
"country_code": "GT",
"country": "Guatemala",
"town": "Solola",
"geo": {
"level": "town",
"pairs": "14.666667 -91.25",
"type": "point"
}
},
"partner_id": 246,
"posted_date": "2015-09-04T08:10:02Z",
"planned_expiration_date": "2015-10-04T08:10:02Z",
"loan_amount": 800,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": [
{
"name": "volunteer_like"
}
]
},
{
"id": 942158,
"name": "Tahira",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 150,
"basket_amount": 0,
"image": {
"id": 1969161,
"template_id": 1
},
"activity": "Sewing",
"sector": "Services",
"themes": [
"Underfunded Areas"
],
"use": "buy a new sewing machine for her clothes sewing center.",
"location": {
"country_code": "PK",
"country": "Pakistan",
"town": "Multan",
"geo": {
"level": "town",
"pairs": "30.195556 71.475278",
"type": "point"
}
},
"partner_id": 247,
"posted_date": "2015-09-04T07:00:05Z",
"planned_expiration_date": "2015-10-04T07:00:05Z",
"loan_amount": 400,
"borrower_count": 1,
"lender_count": 5,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 942166,
"name": "Sareoun's Group",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970161,
"template_id": 1
},
"activity": "Home Appliances",
"sector": "Personal Use",
"themes": [
"Water and Sanitation"
],
"use": "to buy a water filter to provide safe drinking water for their family.\t.",
"location": {
"country_code": "KH",
"country": "Cambodia",
"town": "Kandal",
"geo": {
"level": "town",
"pairs": "13 105",
"type": "point"
}
},
"partner_id": 311,
"posted_date": "2015-09-04T07:00:05Z",
"planned_expiration_date": "2015-10-04T07:00:05Z",
"loan_amount": 225,
"borrower_count": 5,
"lender_count": 0,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 942156,
"name": "Aiza",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 75,
"basket_amount": 0,
"image": {
"id": 1970147,
"template_id": 1
},
"activity": "Farming",
"sector": "Agriculture",
"use": "to buy fertilizers and other farm supplies",
"location": {
"country_code": "PH",
"country": "Philippines",
"town": "Kalibo, Aklan",
"geo": {
"level": "town",
"pairs": "13 122",
"type": "point"
}
},
"partner_id": 145,
"posted_date": "2015-09-04T07:00:03Z",
"planned_expiration_date": "2015-10-04T07:00:03Z",
"loan_amount": 225,
"borrower_count": 1,
"lender_count": 2,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942160,
"name": "Magu Group",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970122,
"template_id": 1
},
"activity": "Used Clothing",
"sector": "Clothing",
"use": "to buy fast moving second hand clothes to meet her customer requirement.",
"location": {
"country_code": "TZ",
"country": "Tanzania",
"town": "Dar es Salaam",
"geo": {
"level": "town",
"pairs": "-6.8 39.283333",
"type": "point"
}
},
"partner_id": 87,
"posted_date": "2015-09-04T07:00:02Z",
"planned_expiration_date": "2015-10-04T07:00:02Z",
"loan_amount": 525,
"borrower_count": 2,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 942142,
"name": "Mwanamiraji",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1970130,
"template_id": 1
},
"activity": "Food Stall",
"sector": "Food",
"use": "to purchase a stock of tomatoes, onions, mangoes and green vegetables for resale",
"location": {
"country_code": "KE",
"country": "Kenya",
"town": "Tiribe",
"geo": {
"level": "town",
"pairs": "1 38",
"type": "point"
}
},
"partner_id": 164,
"posted_date": "2015-09-04T06:30:04Z",
"planned_expiration_date": "2015-10-04T06:30:04Z",
"loan_amount": 200,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
},
{
"id": 940065,
"name": "Tubogorane Group",
"description": {
"languages": [
"fr",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1967147,
"template_id": 1
},
"activity": "Food",
"sector": "Food",
"themes": [
"Conflict Zones"
],
"use": "to increase his working capital and buy a large quantity of fruit and cheese for sale.",
"location": {
"country_code": "BI",
"country": "Burundi",
"town": "Bujumbura",
"geo": {
"level": "town",
"pairs": "-3.5 30",
"type": "point"
}
},
"partner_id": 162,
"posted_date": "2015-09-04T06:20:05Z",
"planned_expiration_date": "2015-10-04T06:20:05Z",
"loan_amount": 3050,
"borrower_count": 19,
"lender_count": 0,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 940076,
"name": "Wend Loiim Taore 2 Group",
"description": {
"languages": [
"fr",
"en"
]
},
"status": "fundraising",
"funded_amount": 50,
"basket_amount": 0,
"image": {
"id": 1967173,
"template_id": 1
},
"activity": "Clothing Sales",
"sector": "Clothing",
"use": "to buy pagnes (traditional, wrap-around clothing) and soap for sale.",
"location": {
"country_code": "BF",
"country": "Burkina Faso",
"town": "Ouagadougou Boulmiougou",
"geo": {
"level": "town",
"pairs": "13 -2",
"type": "point"
}
},
"partner_id": 398,
"posted_date": "2015-09-04T06:20:05Z",
"planned_expiration_date": "2015-10-04T06:20:05Z",
"loan_amount": 1850,
"borrower_count": 5,
"lender_count": 2,
"bonus_credit_eligibility": false,
"tags": []
},
{
"id": 942145,
"name": "Adham",
"description": {
"languages": [
"en"
]
},
"status": "fundraising",
"funded_amount": 25,
"basket_amount": 0,
"image": {
"id": 1970127,
"template_id": 1
},
"activity": "Barber Shop",
"sector": "Services",
"use": "to buy new salon equipment.",
"location": {
"country_code": "PS",
"country": "Palestine",
"town": "Bethlehem",
"geo": {
"level": "town",
"pairs": "31.92157 35.203285",
"type": "point"
}
},
"partner_id": 289,
"posted_date": "2015-09-04T06:10:04Z",
"planned_expiration_date": "2015-10-04T06:10:04Z",
"loan_amount": 3000,
"borrower_count": 1,
"lender_count": 2,
"bonus_credit_eligibility": false,
"tags": [
{
"name": "user_favorite"
}
]
},
{
"id": 941929,
"name": "Silvia Yesenia",
"description": {
"languages": [
"es",
"en"
]
},
"status": "fundraising",
"funded_amount": 0,
"basket_amount": 0,
"image": {
"id": 1969848,
"template_id": 1
},
"activity": "Retail",
"sector": "Retail",
"themes": [
"Conflict Zones"
],
"use": " to buy vegetables, legumes, staple grains and meat, amongst other items, to offer a better service to her customers",
"location": {
"country_code": "SV",
"country": "El Salvador",
"geo": {
"level": "country",
"pairs": "13.833333 -88.916667",
"type": "point"
}
},
"partner_id": 81,
"posted_date": "2015-09-04T06:10:03Z",
"planned_expiration_date": "2015-10-04T06:10:03Z",
"loan_amount": 500,
"borrower_count": 1,
"lender_count": 0,
"bonus_credit_eligibility": true,
"tags": []
}
]
}

最佳答案

loans 数组位于顶级 JSON 对象中,因此:

NSArray *loans = jsonObject[@"loans"];
for (NSDictionary *loan in loans) {
NSNumber *ident = loan[@"id"];
NSString *name = loan[@"name"];
NSDictionary *description = loan[@"description"];
NSDictionary *location = loan[@"location"];
NSString *country = location[@"country"];
// etc.
}

关于objective-c - JSON Objective-c - 对象和数组的组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32395624/

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