首页 \ 问答 \ NSMutableArray来自json的数组(NSMutableArray to array from json)

NSMutableArray来自json的数组(NSMutableArray to array from json)

我需要将NSMutableArray从JSON转换为NSArray。 我加载了JSON并将其放在NSMutableArray中。

NSMutableArray *banner = [[NSMutableArray alloc] init];
banner = [responseObject objectForKey:@"banner"];

这是测试循环:

for(int i = 0; i < [slider count]; i++) {
      NSLog(@"%@", [[banner objectAtIndex:i] objectForKey:@"resim"]);      }

这是来自JSON的日志:

(
        {
        id = 1;
        resim = "http://localhost/sample_Files/banner_api/1.jpg";
    },
        {
        id = 2;
        resim = "http://localhost/sample_Files/banner_api/2.jpg";
    },
        {
        id = 3;
        resim = "http://localhost/sample_Files/banner_api/3.jpg";
    }
)

我想将所有这些设置为下面的NSArray:

NSArray *allImages = @[@"http://localhost/sample_Files/banner_api/1.jpg",@"http://localhost/sample_Files/banner_api/2.jpg",@"http://localhost/sample_Files/banner_api/3.jpg"];

我怎样才能做到这一点?


I need to convert an NSMutableArray to an NSArray from JSON. I loaded the JSON and put it in an NSMutableArray.

NSMutableArray *banner = [[NSMutableArray alloc] init];
banner = [responseObject objectForKey:@"banner"];

This is test for loop:

for(int i = 0; i < [slider count]; i++) {
      NSLog(@"%@", [[banner objectAtIndex:i] objectForKey:@"resim"]);      }

This is log from the JSON:

(
        {
        id = 1;
        resim = "http://localhost/sample_Files/banner_api/1.jpg";
    },
        {
        id = 2;
        resim = "http://localhost/sample_Files/banner_api/2.jpg";
    },
        {
        id = 3;
        resim = "http://localhost/sample_Files/banner_api/3.jpg";
    }
)

I want to set all of this to be like the below NSArray:

NSArray *allImages = @[@"http://localhost/sample_Files/banner_api/1.jpg",@"http://localhost/sample_Files/banner_api/2.jpg",@"http://localhost/sample_Files/banner_api/3.jpg"];

How can I do this?


原文:https://stackoverflow.com/questions/33816679
更新时间:2022-06-03 19:06

最满意答案

你在扩展PDO吗? 当我想实现一个PDO对象时,我写这个:

$pdoObj = new PDO(
            'mysql:dbname=' . DB_NAME .
            ';host=' . HOST_NAME . ";",
            USER,
            PWD,
            array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
        );

Are you extending PDO? When i want to instanciate a PDO object i write this:

$pdoObj = new PDO(
            'mysql:dbname=' . DB_NAME .
            ';host=' . HOST_NAME . ";",
            USER,
            PWD,
            array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
        );

相关问答

更多
  • 在提出一个更普遍的问题之后 ,这似乎是不可能的。 我很确定直接在浏览器中打开的文件的标题行为。 如果您尝试使用上述标题保存文件,则将正确填充文件名。 After asking a more generalized question, it would seem it's impossible. I'm fairly certain the title behavior for files opened directly in the browser. If you attempt to save the f ...
  • 当我看着你的代码时,我看到很多奇怪的事情。 你说你需要UTF-8,但是你使用BaseFont.CP1252而不是BaseFont.IDENTITY_H (这是你使用Unicode时需要的“编码”)创建一个BaseFont对象。 您使用标准的Type 1字体Courier,这是一种不知道如何渲染é,è,à...以及从未嵌入的字体的字体。 如文档所述,在这种情况下, BaseFont.EMBEDDED参数将被忽略! 您不要将此字体与具有实际内容的对象一起使用。 将实际内容放入使用默认字体“Helvetica”创 ...
  • 元命令是错误的。 它应该是 要么 (没有http-equiv)。 但请注意,对字符集使用元命令并不能保证所需的字符集确实被使用。 实际的http头可以用它自己的字符集覆盖这个设置。 此外,关于您的评论,它的正确渲染,请注意,Web浏览器可能会使用不同的算法来确定编码比DLL。 修正元命令可能有帮助,也可能没有帮助。 Th ...
  • 抱歉,上面的链接失败了。 最后,我们发现将PDF作为包装在JSON中的二进制数据发送不起作用。 该服务的创建者发现他们的框架正在轻微地操纵二进制数据并转换一些字符。 他们最终切换到Base 64编码,效果很好。 Sorry the above link failed. In the end we found that sending the PDF as binary data wrapped in JSON did not work very well. The creators of the servi ...
  • 原来FontDescriptor字典中的Flags很重要。 对于Times,需要设置非符号标志(第6位)。 Times实际上是使用TrueType字体排版的事实与它无关。 要使用字体的内置编码,不应设置Type1 Font字典的Encoding条目。 如果它包含非空的Differences数组,或者Adobe Reader将出错,则只能添加Encoding字典(省略BaseEncoding )。 通过这些预防措施,生成的PDF可在上面列出的所有9个查看器应用程序中正确显示 Turns out the Fla ...
  • 5 0 obj<> [...] BT /F1 24 Tf 100 100 Td (ąčęėį šąčįžė)Tj ET 如何更改此文档以使字符正确显示? 除了/编码带有/差异的字典之外,最有可能是将@Xinwang设置为编码的最简单的方法,我想指出你可能还有一些额外的问题:并非所有字符都有一个关联的字形/ Helvetica或任何其他核心标准14字体! 参看 规范ISO 32000-1 ; 第9.6.2.2 ...
  • 为了回答我自己的问题,我转到了Perl PDF :: Extract,它正在运行。 to answer my own question, I moved to Perl PDF::Extract and it's working.
  • 你在扩展PDO吗? 当我想实现一个PDO对象时,我写这个: $pdoObj = new PDO( 'mysql:dbname=' . DB_NAME . ';host=' . HOST_NAME . ";", USER, PWD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8") ); Are you exte ...
  • 我不认为你的字符串转换例程rawStringToBuffer()做你想要的。 您正在将文件作为文本读取,将UTF-8转换为UTF-16。 但是rawStringToBuffer()只取每个UTF-16字符的低位字节并丢弃高位字节,这不是逆变换。 这适用于7位ASCII数据,但不适用于其他字符。 将字符串转换为UTF-8的最佳方法是使用TextEncoder API (并非所有浏览器都支持,但可以使用polyfill)。 但是,不需要将数据从UTF-8转换回来。 只需使用FileReader.readAsAr ...
  • 此插件使用jsPDF作为PDF生产者。 这是该插件的一个已知问题,它没有真正的unicode支持。 只支持几个unicode字符(如德语变音符号)。 This plugin uses jsPDF as PDF producer. It is a known issue of that plugin, that it has no real unicode support. Only a few unicode characters (as german umlauts) are supported.

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。