Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 除NSJSONWRITINGPRETTypted之外的其他选项?_Ios_Nsjsonserialization - Fatal编程技术网

Ios 除NSJSONWRITINGPRETTypted之外的其他选项?

Ios 除NSJSONWRITINGPRETTypted之外的其他选项?,ios,nsjsonserialization,Ios,Nsjsonserialization,我使用以下行将NSDictionary转换为JSONNSData: NSData *jsonData = [NSJSONSerialization dataWithJSONObject:answers options:NSJSONWritingPrettyPrinted error:&a

我使用以下行将
NSDictionary
转换为JSON
NSData

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:answers 
                                                   options:NSJSONWritingPrettyPrinted 
                                                     error:&err];
并将其传递给服务器端,这是一个PHP脚本。脚本将JSON字符串读取为:

{
  "A" : "1941",
  "D" : "1699",
  "B" : "1949",
  "E" : "1823",
  "C" : "1999"
}
如何将JSON字符串格式化为1行,如下所示

{"A" : "1941", "D" : "1699", "B" : "1949", "E" : "1823", "C" : "1999"}
除了
nsjsonwritingprettypted
之外,还有其他选项吗?

quot

如果未设置此选项,将生成最紧凑的JSON表示


如果不想在写入选项掩码中设置任何位,只需为该参数传递零。(或者在Swift中,一个空选项集,看起来就像一个空数组:
[]

除了调试之外,您不应该使用
NSJSONWritingPrettyPrinted
。您可以传入
选项:0
(见下文)以获得缩小的JSON

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:answers options:0 error:&err];
要验证这一点,您可以将其转换为字符串并
NSLog
it

NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
除了
NSJSONWritingPrettyPrinted
,没有其他选项:

typedef NS_OPTIONS(NSUInteger, NSJSONWritingOptions) {
    NSJSONWritingPrettyPrinted = (1UL << 0)
} NS_ENUM_AVAILABLE(10_7, 5_0);
typedef NS_选项(NSUInteger、NSJSONWritingOptions){

NSJSONWritingPrettyPrinted=(1UL不指定该选项。
选项:
可以为零。