• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >ios > iOS在jsonModel中如何获取嵌套数组的数据?

iOS在jsonModel中如何获取嵌套数组的数据?

作者:佚名 字体:[增加 减小] 来源:互联网 时间:2017-06-05

佚名通过本文主要向大家介绍了ios jsonmodel,jsonmodel,web api jsonmodel,ios 数组,ios 数组排序等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题: iOS 在jsonModel中如何获取嵌套数组的数据?
描述:

小弟的model定义如下:

@class cartitems;
@class giftItems;
@class specification;
@class promotions;



@interface THWShoppingCartModel : JSONModel
@property (nonatomic, assign) NSInteger discountPrice;//优惠立减

@property (nonatomic, assign) NSInteger quantity;//商品数量

@property (nonatomic, assign) NSInteger id;//ID

@property (nonatomic, assign) NSInteger effectiveQuantity;//有效商品数

@property (nonatomic, assign) NSInteger freightPrice;//运费

@property (nonatomic, assign) NSInteger effectivePrice;//有效金额

@property (nonatomic, strong) NSArray<giftItems*> *giftItems; //订单项

@property (nonatomic, strong) NSArray<cartitems*> *cartItems; //礼物项

@property (nonatomic, assign) NSInteger effectivePoint;//有效商品积分
@end


@interface cartitems : JSONModel

@property (nonatomic, assign) NSString* id; //订单ID

@property (nonatomic, assign) NSString *productId; //shangpinID

@property (nonatomic, copy) NSString *unit;//单位

@property (nonatomic, assign) NSString *quantity; //数量

@property (nonatomic, assign) NSString *discount;//折扣金额

@property (nonatomic, copy) NSString *tenantName;//商家名称

@property (nonatomic, copy) NSString *tenantId;//商家ID

@property (nonatomic, assign) NSString *price;//折后单价

@property (nonatomic, assign) NSString *subTotal;//金额小计

@property (nonatomic, copy) NSString *fullName;//全名

@property (nonatomic, copy) NSString *thumbnail;//缩略图

@property (nonatomic, strong) NSArray<specification*> *specification; //促销

@property (nonatomic, strong) NSArray<promotions*> *promotions; //规格

@property (nonatomic, assign) BOOL selected; //是否选择

@property (nonatomic, copy) NSString *name;//规格值

@property(nonatomic,copy) NSString *coupon;//是否可领卷

@end


@interface giftItems : JSONModel
@property(copy,nonatomic)NSString *id    ;                    //ID
@property (nonatomic, assign) NSUInteger productId    ;        //商品Id
@property(copy,nonatomic)NSString * fullName;                //全名
@property(copy,nonatomic)NSString *unit;                    //单位
@property(copy,nonatomic)NSString *thumbnail;                //缩略图
@property(copy,nonatomic)NSString *quantity;                //数量
@end


@interface specification : JSONModel
@property (nonatomic, assign) NSUInteger id;            //规格Id
@property(copy,nonatomic)NSString *name;                //规格名称
@end


@interface promotions : JSONModel
@property (nonatomic, assign) NSUInteger id;            //促销Id
@property(copy,nonatomic)NSString *name;                //促销名称
@end

现在需要用:

-(void)parseShoppingCartModelProfile:(NSArray*) cartItems
{
    if(!_moduleDic)
        _moduleDic = [NSMutableDictionary new];
    for (cartitems *item in cartItems) {
        @try {
            NSString *tentid = [NSString stringWithFormat:@"%@",item.tenantId];
            if(![_moduleDic.allKeys containsObject:tentid])
            {
                [_moduleDic setValue:item forKey:tentid];
            }
            else
            {
                [((NSMutableArray *)_moduleDic[tentid]) addObject:item];
            }
        } @catch (NSException *exception) {
            NSLog(@"%@",exception.description);
        }
    }
}

这个方法获取循环遍历处理THWShoppingCartModel NSArray<cartitems> cartItems 中每个成员的数据,但是无论如何都获取不到item.tenantId和其他cartItems model的数据,总是提示: -[__NSCFDictionary tenantId]: unrecognized selector sent to instance 0x7fdf9e0a3fa0,请问大神门如何处理?


解决方案1:

首先根据报错内容, 比较明确的是, 你项目中 cartItems 中的每个元素都是一个 NSDictionary.

建议你向上寻找对应的数据源的正确性.


分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • iOS在jsonModel中如何获取嵌套数组的数据?

相关文章

  • 2017-06-05 iphone4价格走势图iPhone4启动图变形!
  • 2017-06-05 各位大神,我写了一个socket服务端,想,启动App,就监听客户端,并与其连接,应该怎样做
  • 2017-06-05 TableView控件在TableView滑到底部加载新的数据时的策略
  • 2017-06-05 请问各位大神,在OC中,这是个什么语法格式。
  • 2017-06-05 什么时候看到的月亮最大xib看不到布局
  • 2017-06-05 切换跟控制器后。上一个控制器presentViewController子控制器的VIew还在。为什么?
  • 2017-06-05 Validate成功,上传appstore出错:ERRORITMS-90167:"Noappbundlesfoundinthsepack
  • 2017-06-05 拿到一个tableview的高度,设置另一个tableview的一个cell的高度
  • 2017-06-05 iOS基础控件iOS上ScrollView上的Button问题
  • 2017-06-05 iOS反转颜色

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • iOS逆向工程:远程控制App,配合按键精灵做操作。
    • 正在跳转到首页iOS页面跳转问题
    • 在acontroller里面如何调用bcontroller里面的一个方法,
    • Swift如何将json按需储存在字典当中?
    • apple-touch-startup-image不显示
    • iOS接入友盟的微博第三方登录,确认界面马上消失不能点击确认按钮!!!
    • 插入手机数据线,虚拟机中的系统就会死掉
    • 手机客户端开发开发iOSApp是否需要有后端?
    • UIView围绕中心点旋转90后,它的frame是多少?
    • property是什么意思iOS通过property声明的变量的作用域??

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有