gpt4 book ai didi

ios - 如何使图像和字符串的单个数组?在IOS中

转载 作者:行者123 更新时间:2023-12-01 19:55:28 24 4
gpt4 key购买 nike

我正在使用Web_API。我得到了图像和字符串形式的响应。

现在,我想为每个图像和字符串创建一个数组。

这是我的回复:

JsonData={"Menu": [{"GroupMenu":"Student Info","Submenus":[{"title":"User Profile","icon":"http://192.168.0.129:85/Images/NavigationIcon/student_info.png","URL":"StudentProfile"},{"title":"View Attendence","icon":"http://192.168.0.129:85/Images/NavigationIcon/view_attendance.png","URL":"NA"},{"title":"Calender","icon":"http://192.168.0.129:85/Images/NavigationIcon/calender.png","URL":"NA"},{"title":"View TimeTable","icon":"http://192.168.0.129:85/Images/NavigationIcon/timetable.png","URL":"NA"}]},{"GroupMenu":"Transportation","Submenus":[{"title":"Map View","icon":"http://192.168.0.129:85/Images/NavigationIcon/map_view.png","URL":"GoogleMapActivity"},{"title":"Alerts & Notification","icon":"http://192.168.0.129:85/Images/NavigationIcon/alerts&notification.png","URL":"NA"},{"title":"Transportation Desk","icon":"http://192.168.0.129:85/Images/NavigationIcon/transportation_desk.png","URL":"NA"}]},{"GroupMenu":"Notification/Alerts","Submenus":[{"title":"Notification","icon":"http://192.168.0.129:85/Images/NavigationIcon/notification.png","URL":"NA"},{"title":"Principal’s Desk","icon":"http://192.168.0.129:85/Images/NavigationIcon/principal_desk.png","URL":"NA"},{"title":"Digital Diary","icon":"http://192.168.0.129:85/Images/NavigationIcon/digital_diary.png","URL":"NA"},{"title":"Assignment","icon":"http://192.168.0.129:85/Images/NavigationIcon/assignment.png","URL":"NA"}]},{"GroupMenu":"Payment Info","Submenus":[{"title":"View Bill","icon":"http://192.168.0.129:85/Images/NavigationIcon/view_bill.png","URL":"NA"},{"title":"Pay Bill","icon":"http://192.168.0.129:85/Images/NavigationIcon/pay_bill.png","URL":"NA"},{"title":"Online Payment History","icon":"http://192.168.0.129:85/Images/NavigationIcon/onlinepayment_history.png","URL":"NA"}]},{"GroupMenu":"Change Password","Submenus":[{"title":"Change Password","icon":"http://192.168.0.129:85/Images/NavigationIcon/change_password.png","URL":"NA"}]},{"GroupMenu":"Delete User","Submenus":[{"title":"Delete User","icon":"http://192.168.0.129:85/Images/NavigationIcon/delete.png","URL":"NA"}]}]}

预期输出:
studinfo = [NSArray arrayWithObjects:@"Student Info",@"calender",@"Timetable",@"View Attendance",nil];

studimageList = @[[UIImage imageNamed:@"studentinfo.png"], [UIImage imageNamed:@"calendrpng.png"], [UIImage imageNamed:@"timetable.png"],[UIImage imageNamed:@"viewattendance.png"]];

transinfo=[NSArray arrayWithObjects:@"MapView",@"Alert & Notification",@"Transportation Desk",nil];

transimageList = @[[UIImage imageNamed:@"mapview.png"], [UIImage imageNamed:@"alertsnotification.png"], [UIImage imageNamed:@"transportationdesk.png"]];

notificationinfo=[NSArray arrayWithObjects:@"Notification",@"Principal's Desk",@"Digital Diary",@"Assignment",nil];

notificationimageList=@[[UIImage imageNamed:@"notification.png"], [UIImage imageNamed:@"principalsdesk.png"], [UIImage imageNamed:@"digitaldiary.png"],[UIImage imageNamed:@"assignment.png"]];

payinfo=[NSArray arrayWithObjects:@"View Bill",@"Pay Bill",@"Online Payment History",nil];

payimageList = @[[UIImage imageNamed:@"viewbill.png"],[UIImage imageNamed:@"paybill.png"],[UIImage imageNamed:@"onlinepaymenthistory.png"]];


changepassinfo=[NSArray arrayWithObjects:@"Change Password",nil];

changepassimageList = @[[UIImage imageNamed:@"changepassword.png"]];

deleteuserinfo=[NSArray arrayWithObjects:@"Delete User",nil];

deleteuserimageList = @[[UIImage imageNamed:@"delete.png"]];

最佳答案

                                   // json can be NSDictionary *json
id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

// parsing data from main dict (JSON data)
NSDictionary *innerDict1 = [json valueForKey:@"Menu"];

// now parsing data from menu dict
NSDictionary *innerDict2 = [innerDict1 valueForKey:@"Submenus"];

// parsing node of Submenus dict, can pass any key inside legs
NSLog(@"values: %@", [innerDict2 valueForKey:@"title"]);

// getting values inside mutable array

groupmenu = [innerDict1 valueForKey:@"GroupMenu"];

submenu = [innerDict2 valueForKey:@"title"];

icon = [innerDict2 valueForKey:@"icon"];

url = [innerDict2 valueForKey:@"URL"];
for(int i=0;i<groupmenu.count;i++)
{
switch(i)
{
case 0:
studinfo=submenu[i];
studimage=icon[i];

NSLog(@"studinfo= %@",studinfo);
NSLog(@"studimage %@",studimage);
break;

case 1:
transinfo=submenu[i];
transimage=icon[i];

NSLog(@"transinfo= %@",transinfo);
NSLog(@"transimage %@",transimage);
break;

case 2:
notificationinfo=submenu[i];
notificationimage=icon[i];

NSLog(@"notificationinfo= %@",notificationinfo);
NSLog(@"notificationimage= %@",notificationimage);
break;
case 3:
paymentinfo=submenu[i];
paymentimage =icon[i];

NSLog(@"paymentinfo= %@",paymentinfo);
NSLog(@" paymentimage = %@",paymentimage );
break;
case 4:
changepass=submenu[i];
changepassimage=icon[i];

NSLog(@"changepass= %@",changepass);
NSLog(@"changepassimage= %@",changepassimage);
break;
case 5:
delete=submenu[i];
deleteimage= icon[i];

NSLog(@"deleteimage= %@",deleteimage);
break;
}
}

关于ios - 如何使图像和字符串的单个数组?在IOS中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42922577/

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