07-21-2023, 08:17 PM
Do:
NSData *data = [yourString dataUsingEncoding:NSUTF8StringEncoding];
then feel free to proceed with `NSJSONSerialization:JSONObjectWithData`.
---
###Correction to the answer regarding the NULL terminator
Following the comments, official documentation, and [verifications](
1. As documented by [dataUsingEncoding:](
>###Return Value
The result of invoking `dataUsingEncoding:allowLossyConversion:` with NO as the second argument
2. As documented by [getCString:maxLength:encoding:](
>note that the data returned by `dataUsingEncoding:allowLossyConversion:` is not a strict C-string since it **does not have a NULL terminator**
NSData *data = [yourString dataUsingEncoding:NSUTF8StringEncoding];
then feel free to proceed with `NSJSONSerialization:JSONObjectWithData`.
---
###Correction to the answer regarding the NULL terminator
Following the comments, official documentation, and [verifications](
[To see links please register here]
), this answer was updated regarding the removal of an alleged NULL terminator:1. As documented by [dataUsingEncoding:](
[To see links please register here]
):>###Return Value
The result of invoking `dataUsingEncoding:allowLossyConversion:` with NO as the second argument
2. As documented by [getCString:maxLength:encoding:](
[To see links please register here]
) and [cStringUsingEncoding:]([To see links please register here]
):>note that the data returned by `dataUsingEncoding:allowLossyConversion:` is not a strict C-string since it **does not have a NULL terminator**