GCKJSONUtils 类
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
此类继承 NSObject。
+ (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 }
。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eThe \u003ccode\u003eGCKJSONUtils\u003c/code\u003e class provides utility methods for working with JSON data in iOS applications.\u003c/p\u003e\n"],["\u003cp\u003eIt offers functionalities to parse JSON strings into objects (NSArray or NSDictionary) with or without error handling.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eGCKJSONUtils\u003c/code\u003e enables writing object hierarchies (NSArray or NSDictionary) to JSON strings.\u003c/p\u003e\n"],["\u003cp\u003eIt includes methods to compare two JSON strings or objects for equivalence, disregarding key order within JSON objects.\u003c/p\u003e\n"]]],["The `GCKJSONUtils` class provides methods for handling JSON data. Key actions include parsing a JSON string into an object using `parseJSON:` or `parseJSON:error:`. It also allows writing an object hierarchy into a JSON string with `writeJSON:`. Additionally, the class can test if two JSON strings are equivalent using `isJSONString:equivalentTo:` or if two JSON objects are equivalent with `isJSONObject:equivalentTo:`, while ignoring key order differences within JSON objects.\n"],null,["# GCKJSONUtils Class\n\n[Class Methods](#pub-static-methods) \nGCKJSONUtils Class Reference \n\nOverview\n--------\n\nUtility methods for working with JSON data.\n\nInherits NSObject.\n\n|---------------|--------------------------------------------------------------------------------------------------------------------------|\n| Class Method Summary -------------------- ||\n| (nullable id) | + [parseJSON:](/cast/docs/reference/ios/interface_g_c_k_j_s_o_n_utils#a8762d8d1a23b97c3d456dfa3bb981913) |\n| | Parses a JSON string into an object. [More...](#a8762d8d1a23b97c3d456dfa3bb981913) |\n| ||\n| (nullable id) | + [parseJSON:error:](/cast/docs/reference/ios/interface_g_c_k_j_s_o_n_utils#a264eda897ce3f8df4bbb6191a763d814) |\n| | Parses a JSON string into an object. [More...](#a264eda897ce3f8df4bbb6191a763d814) |\n| ||\n| (NSString \\*) | + [writeJSON:](/cast/docs/reference/ios/interface_g_c_k_j_s_o_n_utils#ad329d350c0a2035c39d5ec7394f8b94d) |\n| | Writes an object hierarchy of data to a JSON string. [More...](#ad329d350c0a2035c39d5ec7394f8b94d) |\n| ||\n| (BOOL) | + [isJSONString:equivalentTo:](/cast/docs/reference/ios/interface_g_c_k_j_s_o_n_utils#a2f6308cd0106982730c795103d1db058) |\n| | Tests if two JSON strings are equivalent. [More...](#a2f6308cd0106982730c795103d1db058) |\n| ||\n| (BOOL) | + [isJSONObject:equivalentTo:](/cast/docs/reference/ios/interface_g_c_k_j_s_o_n_utils#aac1932e69f8e470853261dc82c079e41) |\n| | Tests if two JSON objects are equivalent. [More...](#aac1932e69f8e470853261dc82c079e41) |\n| ||\n\nMethod Detail\n-------------\n\n|----------------------------|---|---------------|--------|---|\n| + (nullable id) parseJSON: | | (NSString \\*) | *json* | |\n\nParses a JSON string into an object.\n\nParameters\n:\n\n |------|---------------------------|\n | json | The JSON string to parse. |\n\n\nReturns\n: The root object of the object hierarchy that represents the data (either an [**NSArray**](https://goo.gl/q3tY5n) or an [**NSDictionary**](https://goo.gl/0kFoNp)), or `nil` if the parsing failed. \n\n|------------------------------------------------------------------------------------------------------------------------|---|----------------|---------|\n| + (nullable id) [parseJSON:](/cast/docs/reference/ios/interface_g_c_k_j_s_o_n_utils#a8762d8d1a23b97c3d456dfa3bb981913) | | (NSString \\*) | *json* |\n| error: | | (NSError \\*\\*) | *error* |\n| | | | |\n\nParses a JSON string into an object.\n\nParameters\n:\n\n |-------|-----------------------------------------------------------------------------------------------------------------------|\n | json | The JSON string to parse. |\n | error | If not nil, the location at which to store a pointer to an [**NSError**](https://goo.gl/WJbrdL) if the parsing fails. |\n\n\nReturns\n: The root object of the object hierarchy that represents the data (either an [**NSArray**](https://goo.gl/q3tY5n) or an [**NSDictionary**](https://goo.gl/0kFoNp)), or `nil` if the parsing failed. \n\n|----------------------------|---|------|----------|---|\n| + (NSString \\*) writeJSON: | | (id) | *object* | |\n\nWrites an object hierarchy of data to a JSON string.\n\nParameters\n:\n\n |--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|\n | object | The root object of the object hierarchy to encode. This must be either an [**NSArray**](https://goo.gl/q3tY5n) or an [**NSDictionary**](https://goo.gl/0kFoNp). |\n\n\nReturns\n: An [**NSString**](https://goo.gl/5dXzU6) containing the JSON encoding, or `nil` if the data could not be encoded. \n\n|------------------------|---|---------------|------------|\n| + (BOOL) isJSONString: | | (NSString \\*) | *actual* |\n| equivalentTo: | | (NSString \\*) | *expected* |\n| | | | |\n\nTests if two JSON strings are equivalent.\n\nThis does a deep comparison of the JSON data in the two strings, but ignores any differences in the ordering of keys within a JSON object. For example, `{ \"width\":64, \"height\":32 }` is considered to be equivalent to `{ \"height\":32, \"width\":64 }`. \n\n|------------------------|---|------|------------|\n| + (BOOL) isJSONObject: | | (id) | *actual* |\n| equivalentTo: | | (id) | *expected* |\n| | | | |\n\nTests if two JSON objects are equivalent.\n\nThis does a deep comparison of the JSON data in the two objects, but ignores any differences in the ordering of keys within a JSON object. For example, `{ \"width\":64, \"height\":32 }` is considered to be equivalent to `{ \"height\":32, \"width\":64 }`."]]