动态分配结构

I have a struct:

type person struct{
    FirstN      [10]byte
    Last Name   [10]byte
    Address     [15]byte
    zip         [6]byte
}

Then I have Map

   xyz = [01:aaaaaaaaaabbbbbbbbbbccccccccccccccc123456]

This map is exactly the same as my struct. Basically if I overlay my structure with the string in the map it is an exact match.

I am trying to get a JSON string for this data, using Marshal. But for that (as I understand it) I need to update the data in the map into the struct and then pass the structure pointer to Marshal

But I cannot find any way to get the data from the map with key '01' which is a string and initialize my structure with it. I do not want to add a code to update each field in the structure by parsing the string from the map. Is there a way to do it or hardcoding is the only option.

Also is there a way to create a JSON string from a map string directly?

That's not json data. However, the binary.Read function will decode arbitrary fixed sized values from a binary stream following the struct layout.

data := []byte("aaaaaaaaaaaaaaaaaaaaccccccccccccccc123456")
err := binary.Read(bytes.NewReader(data), binary.LittleEndian, &p)

https://play.golang.org/p/-I_XhUCvNN