Answer the question
In order to leave comments, you need to log in
How to process partially json structure in go?
Good day to all!
There is a task to parse json file. Problems in parsing There is no whole file, but there is a problem in parsing part of the file! View file:
-Head category
+ subcategory...
++subcategory parameters and more nested categories...
So, there are 15 head categories in the file, but at the moment I need only 10! How should I best handle the source file: create an array/map/whatever?
At the moment, to parse the entire file, the mem has the construction:
var str1 Menu
err = json.Unmarshal(bs,&str1)
if err!= nil{
fmt.Println("Unmarshal error = ", err.Error())
}
type Menu struct {
Catalog []struct {
MainCategoryName string `json:"mainCategoryName"`
MainCategorySlice []struct {
CurrentCategoryName string `json:"currentCategoryName"`
CurrentCategorySlice []struct {
EndCategoryName string `json:"currentCategoryName"`
} `json:"currentCategorySlice"`
} `json:"mainCategorySlice"`
} `json:"catalog"`
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question