My application uses NSTask to start a Python script, then the script returns an array via NSPipe. I read the data, stick it in a string, and display it:
NSMutableData *data = [[NSMutableData alloc] init];
NSData *readData;
while ((readData = [readHandle availableData])&& [readData length]) {
[data appendData: readData];
}
NSString *string = [[NSString alloc]
initWithData: data
encoding: NSUTF8StringEncoding];
That's all fine, but I realized I really need to keep it as an array - not a string. I can't find a method that initiates array from data (data returned from NSPipe). How can I do that? The closest thing I found is possibly using:
[NSPropertyListSerialization dataWithPropertyList:format:options:error:]
... but I don't need a "property list" per se. Do I have to convert the data to plist first?
EDITED: I just realized it's more complicated than I thought. Python returns an array of dictionaries, in the dictionary there are strings. These strings can have commas and other chars, so I don't think I can use a "," separator to break it up.
in Python:
msg_set = []
msg_set = [
dict(mts="t,s1", mfrom="f@ro,m1", msbj="msb,j1", mbody="bod,y1", mid="i,d1"),
dict(mts="ts2", mfrom="from2", msbj="msb,j2", mbody="body2", mid="id2")
]
print msg_set # <- this is what python returns