Conversion between Json,string,map

Source: Internet
Author: User
Tags string to json

If the format of the string is a map or JSON type

String to JSON

Jsonobject jasonobject = Jsonobject.fromobject (str);

String goto Map

Jsonobject jasonobject = Jsonobject.fromobject (str);
Map map = (map) jasonobject;

There is a Chinese garbled solution for passing data between Web pages:

For example, the request interface returns a map or JSON data containing the Chinese

1, first turn map or JSON into string format, if it is a map type, first turn to JSON Jsonobject json=new jsonobject (map); Json.tojsonstring (); turn into string format

2, using Urlencoder.encoder (str, "UTF-8") or "GBK" to encrypt string processing, send encrypted str

3, on the receiving end, after receiving STR, urldecoder.decoder (str, "UTF-8") decrypted to normal STR, generally to be converted to JSON need to remove the opening end of the quotation marks, str=str.substring (1,str.length ()-1) , then use Jsonobject.formobject (str) to turn STR into JSON, then map,map map = (map) json.

Conversion between Json,string,map

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.