3

I have a NSString with below format .Currently it is not a valid JSON string .I want to change it as a JSON string and store it in an NSArray. This is my NSString.

[, {"Agent":" Visitor", "Time":"03:18 AM", "Message":"Msg from : file:///Users/satheesanop/Desktop/something.htmlIP Address : 182.72.139.142Country : IndiaCity : MadrasRegionName : Tamil N?duBrowser : Chrome 22OS : Mac", }, {"Agent":" agent name", "Time":"03:21 AM", "Message":"Thank you for contacting us.How may i help you ?", }, {"Agent":" Visitor", "Time":"03:22 AM", "Message":"Some message.", }]

Any help is appreciated .

4

2 回答 2

6

您需要转换NSStringNSData使用dataUsingEncoding:方法。

然后使用该JSONObjectWithData方法并将其添加到数组中。

NSArray *arrayJson = [NSArray arrayWithObjects:[NSJSONSerialization JSONObjectWithData:data options:0 error:nil],nil];
于 2012-10-30T13:24:40.850 回答
0

弄清楚了 ..

Mystr = [Mystr stringByReplacingOccurrencesOfString:@"[,"  withString:@"["];
Mystr = [Mystr stringByReplacingOccurrencesOfString:@", }" withString:@"}"];

谢谢大家。

于 2012-10-30T13:22:17.280 回答