Gofasion: A lightweight JSON data parsing library with chained call styles

Source: Internet
Author: User
Gofasion is a lightweight parsing library that facilitates the parsing of interface JSON data in the development process, and its greatest feature is the support of chained calls, which means that the target key name and key value can be obtained directly without having to pre-define the structure of the data. # # # Open Source [https://github.com/Anderson-Lu/gofasion] (https://github.com/Anderson-Lu/gofasion) # # # install ' Shellgo get Github.com/anderson-lu/fasion/gofasion ' # # # Quick Start ' shellpackage mainimport ("github.com/anderson-lu/fasion/ Gofasion "FMT")//rule data var Testjson = ' {' name ': ' foo ', ' value ': 1, ' second_level ': {' name ': 2}, ' Second_array ': [ 1,2,3,4,5,6,7], "bool": True, "Value64": 1234567890} '//irregular data var testJson2 = ' ["," Helloword ", {" Name ":" Demo "}] ' Func Main () {fsion: = gofasion. Newfasion (Testjson)//Output "foo" FMT. Println (fsion. Get ("name"). VALUESTR ())//Output 1 FMT. Println (fsion. Get ("value"). Valueint ())//output {\ "name\": \ "foo\", \ "value\": 1 ...} fmt. Println (fsion. Json ()) I32: = Fsion. Get ("value"). ValueInt32 () fmt. Println (i32) i64: = Fsion. Get ("Value64"). ValueInt64 () fmt. Println (i64) Second_fson: = Fsion. Get ("Second_level") fmt. Println (Second_fson. Get ("name"). VALUESTR ())///Array data traversal second_array: = fsion. Get ("Second_array"). Array () for _, V: = Range Second_array {fmt. Println (V.valueint ())}boolval: = Fsion. Get ("bool"). Valuestr () fmt. Parsing fsion2 for PRINTLN (boolval)//Irregular data: = Gofasion. Newfasion (testJson2) Elems: = Fsion2. Array () fmt. Println (Elems[0]. Valueint ()) fmt. Println (Elems[1]. Valueint ()) fmt. Println (Elems[2]. Valuestr ()) fmt. Println (Elems[3]. JSON ())//traditional struct parsing var iter struct {name string ' JSON: ' name ' ' value int ' JSON: ' Value ' '}fsion. Value (&iter) fmt. PRINTLN (ITER). Name) fmt. PRINTLN (ITER). Value)} ' # # # version ' V1 ' base version, providing common basic functions # # # Contribution Welcome to the valuable issue, you can also submit a merger request, hoping to make a revenue for all Golang developers Open Source Library. # # # License mit Licence97 click  ∙  1 likes  

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.