GCKJSONUtils 類別參考資料
總覽
處理 JSON 資料的公用程式方法。
繼承 NSObject。
類別方法摘要 | |
(nullable id) | + parseJSON: |
將 JSON 字串剖析為物件。更多... | |
(nullable id) | + parseJSON:error: |
將 JSON 字串剖析為物件。更多... | |
(NSString *) | + writeJSON: |
將資料的物件階層寫入 JSON 字串。更多... | |
(BOOL) | + isJSONString:equivalentTo: |
測試兩個 JSON 字串是否相等。更多... | |
(BOOL) | + isJSONObject:equivalentTo: |
測試兩個 JSON 物件是否相等。更多... | |
方法詳細資料
+ (nullable id) parseJSON: | (NSString *) | json |
將 JSON 字串剖析為物件。
- Parameters
-
json The JSON string to parse.
- 傳回
- 代表資料的物件階層根物件 (NSArray 或 NSDictionary),如果剖析失敗,則為
nil
。
+ (nullable id) 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 }
。