The playful JSON of Go language

Source: Internet
Author: User
Tags convert string to json string to json

Here, I'm not going to talk about what the official website maps to the structure or anything, just a little bit of my own exploration

The HTML page code is as follows, the following example HTML generic

Convert string to JSON

The target string "{' Eooall ', ' Eooall '}", we will first turn the single quotation mark of this string into double quotation marks and then convert to a byte array. Verified by the Ajax of the page, the code is as follows

str:= "{' Eooall ', ' Eooall '}"

Newstr:=strings. Replace (str, "'", "\" ",-1)

Callback Ajax data

W.writer ([]type (b))

The code is as follows

The results are as follows

Map to JSON

The code is as follows

The results are as follows

interface forwarding type, because I am playing the crawler, I use go to request other people's interface, and I do not know the structure of the JSON, so I can not write the corresponding structure, and then this operation, can be forwarded what, the use is still very large

The code is as follows

The results are as follows

From the above can be known that the return JSON can use go to provide good or complete their own assembly, the key is to return the data when W. Wreter () is a []byte type of value, just throw the string in it, if the string can be converted to JSON.

The playful JSON of Go language

Related Article

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.