您如何存储"int"? NSMutableArray *或NSMutableDictionary *中的值? JSON数据(以整数形式出现)的长期问题. [英] How do you store "int" values in an NSMutableArray* or NSMutableDictionary*? Chronic problems with JSON data that come in as integers.

查看:177
本文介绍了您如何存储"int"? NSMutableArray *或NSMutableDictionary *中的值? JSON数据(以整数形式出现)的长期问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将"int"值存储在NSMutableArrayNSMutableDictionary中? JSON数据(以整数形式出现)的长期问题.

How do you store "int" values in an NSMutableArray or NSMutableDictionary? Chronic problems with JSON data that come in as integers.

我应该尝试将这些整数存储为NSNumber对象还是作为包含该整数的字符串存储?

Should I try to store these integers as NSNumber objects or just as strings that contain the integer?

如果我知道值将始终为自然数(数字> = 0,包括零,则为null),对指针执行原始"(int)转换有多危险?

How dangerous is it to do a "raw" (int) conversion on the pointers if I know the values will always be Natural Numbers (numbers>=0 including zero for null.)

我一直使用的整数是数据库中的外键ID.

The integers I'm always working with are Foreign Key Id's from a database.

推荐答案

像这样使用NSNumber:

Use NSNumber like this:

int yourInt = 5;
[myMutableArray addObject:[NSNumber numberWithInt:yourInt]];

或者使用现代的Objective C语法,您可以将以下内容用于表达式:

Or using modern Objective C syntax, you can use the following for expressions:

[myMutableArray addObject:@(2 + 3)];

或者对于单身数字:

[myMutableArray addObject:@5];

这篇关于您如何存储"int"? NSMutableArray *或NSMutableDictionary *中的值? JSON数据(以整数形式出现)的长期问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆