Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSString to JSON string

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 .

like image 410
Sat Avatar asked Dec 04 '25 12:12

Sat


1 Answers

You need to convert NSString to NSData using dataUsingEncoding: method.

then use the JSONObjectWithData method and add it to array.

NSArray *arrayJson = [NSArray arrayWithObjects:[NSJSONSerialization JSONObjectWithData:data options:0 error:nil],nil];
like image 73
Midhun MP Avatar answered Dec 06 '25 05:12

Midhun MP



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!