This is a creation in Article, where the information may have evolved or changed. # library name [Ourjson] (Https://github.com/W1llyu/ourjson) https://github.com/W1llyu/ourjson## official approach to the official approach is primarily a whole JSON put together parsing, A struct must be defined in advance to host or be hosted with a map[string]interface, and the corresponding type is transferred when the value is obtained. However, in some layers of nested JSON scenarios, it is troublesome to define n unwanted structures in advance to obtain a value for a sub-JSON object. Ourjson This library is a bit like Java inside the Jsonobject, below is an example # # example "" Gopackage mainimport ("FMT" "Github.com/w1llyu/ourjson") func main () { Defer func () {if err: = Recover (); Err! = nil {fmt. PRINTLN (Err)}} () Jsonstr: = ' {"user": {"name": "AA", "Age": Ten, "Phone": "12222222222", "emails": ["aa@164.com", " Aa@165.com "]," address ": [{" Number ":" 101 "," now_live ": true},{" number ":" 102 "," now_live ": null}]," account ": {" balance ": 999.9}} ' Jsonobject, err: = Ourjson. Parseobject (JSONSTR) fmt. Println (Jsonobject, err) User: = Jsonobject.getjsonobject ("user") Fmt. PRINTLN (user) name, err: = user. GetString ("name") fmt. PRINTLN (name, err) phone, err: = user. GetInt64 ("Phone") fmt. PRINTLN (phone, err) age, err: = user. GetInt64 ("Age") fmt. Println (age, err) account: = user. Getjsonobject ("account") fmt. PRINTLN (account) balance, err: = account. GetFloat64 ("balance") fmt. Println (balance, err) email1, err: = user. Getjsonarray ("emails"). GetString (0) fmt. Println (EMAIL1, err) Address: = user. Getjsonarray ("Address") fmt. PRINTLN (address) address1nowlive, err: = user. Getjsonarray ("Address"). Getjsonobject (0). Getboolean ("Now_live") fmt. Println (address1nowlive, err) address2, err: = Address. Get (1) fmt. Println (Address2, err) address2nowlive, err: = Address2. Jsonobject (). Getnullboolean ("Now_live") fmt. Println (address2nowlive, Err)} "361 reads
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