Hi,
I tried to convert http.Req.Form to struct, the code is pasted in
http://pastie.org/1145974, what I want is:
if typ is a *reflect.StructType, then convert the json string to
struct
type menu_S struct{
Id int
Name string
Type string
Area string
//Materials []material_S
Materials material_S
Method string
}
type material_S struct{
Food_name string
Amount int
Unit string
}
I want to convert the json string
{"Food_name":"aaa","Amount":"123","Unit":"g"} to material_S
......
case *reflect.StructType:
bs := bytes.NewBufferString(firstStrValue).Bytes()
val := reflect.MakeZero(field.Type)
fmt.Println(reflect.Typeof(val),reflect.Typeof(&val))
if err := json.Unmarshal(bs, val.Interface()); err != nil {
return os.NewError(fmt.Sprintf("Convert "+firstStrValue+" to
"+keyName+" error: %s",err))
}
sValue.FieldByName(keyName).(*reflect.StructValue).Set(val.
(*reflect.StructValue))
But I got error:json: Unmarshal(non-pointer main.material_S).
What should I do?