如何确保首先解析根结构的字段,然后解析嵌入式结构的字段

I have the struct as follows:-

type Inner struct {
    FooInner string `json:"fooInner"`
    BarInner string `json:"barInner,omitempty"`
}

type Root struct {
    Inner
    Foo string `json:"foo"`
    Bar string `json:"bar"`
}

I want the fields of "Root" struct to be parsed first and then the fields of the "Inner" struct. But here the fields of Inner struct is getting parsed first.

If you are asking about JSON marshaling (which is not parsing) and want fields marshaled in a certain order, a marshaler will typically marshal fields in their index order & recurse any embedded structs along the way. Struct field indices - as seen by the reflect package that json.Marhsal uses - are defined by their order of appearance in your code.

So put the fields you want first - and any embedded structs later:

type Root struct {
    Foo string `json:"foo"`
    Bar string `json:"bar"`
    Inner // <- move this last
}

Playground Example

b, _ := json.Marshal(Root{})

{"foo":"","bar":"","fooInner":""}