You could try something like this https://play.golang.org/p/a-4i045QdXX
On Saturday, 26 December 2020 at 17:49:33 UTC zxj1341...@gmail.com wrote: > In fact, the JSON content you pasted here is NOT valid, cause there > shouldn't be more than one root element in a single JSON file (you can try > online > JSON validator <https://jsonformatter.curiousconcept.com/> to validate > your JSON file). > 在2020年12月26日星期六 UTC+8 下午11:06:22<hamsah...@gmail.com> 写道: > >> how to unmarshal more than one json object .. >> >> Here is the code >> data, err := ioutil.ReadFile("file.txt") >> checkError(err) >> x:=string(data) >> fmt.Println(x) >> >> var b1 book >> err1:=json.Unmarshal(data,&b1) >> >> fmt.Printf("Books : %+v", b1) >> checkError(err1) >> if b1.ID==ID { >> >> log.Printf("The book with ID:%d has title: %s, it was publiched at >> date: %s,his author is: %s,it's genre is: %s,it was published by: %s,it's >> language is: >> %s.",b1.ID,b1.Title,b1.PubDate,b1.Author,b1.Genre,b1.Publisher,b1.Language) >> }else{ >> fmt.Println("There is no such book!") >> } >> that's the output if the file has one object >> [image: Screenshot (54).png] >> >> it doesn't work if there are many objects >> [image: Screenshot (53).png] >> >> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/3e6da990-3fdb-4b61-8444-2cdc12e68c16n%40googlegroups.com.