Go Language parsing JSON string

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

Go parse JSON format string type Info struct{    Name string Age    int    Address string} to parse the JSON format string into a struct, simply pass the struct object to the JSON . Unmarshal () function Jsonstr: = ' {' name ': ' Yang ', ' age ': ' Address ': ' Shenzhen '} ' Var myinfo infojson.unmarshal ([]byte ( JSONSTR), &myinfo) Description: In the declaration structure there are two places to note, the following explanation illustrates the first type Info struct{    Name string Age    int    Address The string} variable name must be the same as the JSON string name, and the first letter uppercase, because in the go language, the first letter capitalized to represent global variables, the same reason, Age,address is the same as the second type of Info struct{    myName Stirng ' JSON: ' name ' '    myAge int ' json: ' Age ' '    myAddress string ' JSON: ' Shenzhen ' '} This way, struct variable names can be arbitrarily defined, but must be followed by ' JSON: "Name" and so on, "name" is the corresponding key in the JSON string, myname store the value corresponding to the key can also parse the JSON string to some structure


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.