简体   繁体   中英

Javascript array to NSArray in Xcode

I am very new to Xcode and programming in general. I wrote and app in javascript and html and packaged it in Xcode.

Right now I am trying to take several arrays from the html/javascript document and export them as a csv from the Xcode application. Some of these arrays will be columns and some will be rows. For example...

array1 = {column 1, column 2, column 3}
dataForColumn1 = {row1, row2, row3, row4, row5, row6, row7, row8}
dataForColumn3 = {row1, row2, row3, row4, row5, row6, row7, row8}

The data columns will always have the same number of rows but the lengths of all arrays can vary. I have found some information on how to take an NSArray and export it to a csv file but I have not been successful with it.

In order to do this I would also need to pull the javascript arrays and make them NSArrays. I am also unsure of how to do this in Xcode.

Thanks for the help!

a JavaScript array is actually a JSON array So you can do this using JSON parsing

NSError *error;
NSArray* json = [NSJSONSerialization
                          JSONObjectWithData:[yourArray dataUsingEncoding:NSUTF8StringEncoding]
                          options:NSJSONReadingMutableContainers
                          error:&error];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM