GCKJSONUtils Class
Stay organized with collections
Save and categorize content based on your preferences.
Utility methods for working with JSON data.
Inherits NSObject.
+ (nullable id) parseJSON: |
|
(NSString *) |
json |
|
Parses a JSON string into an object.
- Parameters
-
json | The JSON string to parse. |
- Returns
- The root object of the object hierarchy that represents the data (either an NSArray or an NSDictionary), or
nil
if the parsing failed.
+ (nullable id) parseJSON: |
|
(NSString *) |
json |
error: |
|
(NSError **) |
error |
|
|
| |
Parses a JSON string into an object.
- 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. |
- Returns
- The root object of the object hierarchy that represents the data (either an NSArray or an NSDictionary), or
nil
if the parsing failed.
+ (NSString *) writeJSON: |
|
(id) |
object |
|
Writes an object hierarchy of data to a JSON string.
- Parameters
-
object | The root object of the object hierarchy to encode. This must be either an NSArray or an NSDictionary. |
- Returns
- An NSString containing the JSON encoding, or
nil
if the data could not be encoded.
+ (BOOL) isJSONString: |
|
(NSString *) |
actual |
equivalentTo: |
|
(NSString *) |
expected |
|
|
| |
Tests if two JSON strings are equivalent.
This 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 }
.
+ (BOOL) isJSONObject: |
|
(id) |
actual |
equivalentTo: |
|
(id) |
expected |
|
|
| |
Tests if two JSON objects are equivalent.
This 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 }
.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-18 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-18 UTC."],[[["\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,["[Class Methods](#pub-static-methods) \nGCKJSONUtils Class Reference \n\nOverview \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| + (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 }`."]]