NSJSONSerialization from NSString

后端 未结 4 645
眼角桃花
眼角桃花 2020-12-03 00:41

Is it possible if I have a NSString and I want to use NSJSONSerialization? How do I do this?

4条回答
  •  误落风尘
    2020-12-03 01:27

    First you will need to convert your NSString to NSData by doing the following

    NSData *data = [stringData dataUsingEncoding:NSUTF8StringEncoding];
    

    then simply use the JSONObjectWithData method to convert it to JSON

    id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
    

提交回复
热议问题