GCKJSONUtils 類別參考資料
總覽
使用 JSON 資料的公用程式方法。
沿用 NSObject。
類別方法摘要 | |
(id __nullable) | + parseJSON: |
將 JSON 字串剖析為物件。更多... | |
(id __nullable) | + parseJSON:error: |
將 JSON 字串剖析為物件。更多... | |
(NSString *) | + writeJSON: |
將資料物件物件階層寫入 JSON 字串。更多... | |
(BOOL) | + isJSONString:equivalentTo: |
測試兩個 JSON 字串是否相等。更多... | |
(BOOL) | + isJSONObject:equivalentTo: |
測試兩個 JSON 物件是否相等。更多... | |
方法說明
+ (id __nullable) parseJSON: | (NSString *) | json |
將 JSON 字串剖析為物件。
- Parameters
-
json The JSON string to parse.
- 傳回
- 表示資料的物件階層根物件 (NSArray 或 NSDictionary);如果剖析失敗,則會傳回
nil
。
+ (id __nullable) parseJSON: | (NSString *) | json | |
error: | (NSError **) | error | |
將 JSON 字串剖析為物件。
- Parameters
-
json The JSON string to parse. error If not nil, the location at which to store a pointer to an NSError if the parsing fails.
- 傳回
- 表示資料的物件階層根物件 (NSArray 或 NSDictionary);如果剖析失敗,則會傳回
nil
。
+ (NSString *) writeJSON: | (id) | object |
將資料物件物件階層寫入 JSON 字串。
- Parameters
-
object The root object of the object hierarchy to encode. This must be either an NSArray or an NSDictionary.
- 傳回
- 包含 JSON 編碼的 NSString;如果資料無法編碼,則為
nil
。
+ (BOOL) isJSONString: | (NSString *) | actual | |
equivalentTo: | (NSString *) | expected | |
測試兩個 JSON 字串是否相等。
這會對兩個字串中的 JSON 資料進行深度比較,但忽略 JSON 物件中金鑰順序的任何差異。舉例來說,系統會將 { "width":64, "height":32 }
視為 { "height":32, "width":64 }
。
+ (BOOL) isJSONObject: | (id) | actual | |
equivalentTo: | (id) | expected | |
測試兩個 JSON 物件是否相等。
這會對兩個物件中的 JSON 資料進行深度比較,但忽略 JSON 物件中金鑰的排序差異。舉例來說,系統會將 { "width":64, "height":32 }
視為 { "height":32, "width":64 }
。