I have a dictionary
I need to generate a JSON string
by using dictionary
. Is it possible to convert it? Can you guys please help on this?
相关问题
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- CALayer - backgroundColor flipped?
- how to split a list into a given number of sub-lis
相关文章
- 现在使用swift开发ios应用好还是swift?
- json_encode 没有把数组转为json
- Livy Server: return a dataframe as JSON?
- JSP String formatting Truncate
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Unexpected end of JSON input from an ajax call
- Where does a host app handle NSExtensionContext#co
Now no need third party classes ios 5 introduced Nsjsonserialization
this code can useful for getting jsondata.
You can pass array or dictionary. Here, I am taking NSMutableDictionary.
To generate a JSON string from a NSDictionary or NSArray, You don't need to import any third party framework. Just use following code:-
As of ISO7 at least you can easily do this with NSJSONSerialization.
NOTE: This answer was given before iOS 5 was released.
Get the json-framework and do this:
myDictionary
will be your dictionary.Here is the Swift 4 version
}
Usage Example
Or if you are sure it is valid dictionary then you can use
Here are categories for NSArray and NSDictionary to make this super-easy. I've added an option for pretty-print (newlines and tabs to make easier to read).
.
.
.