我有一個接收JSON圍棋REST服務,我需要編輯JSON,所以我可以做兩個不同的結構REST服務。操縱JSON在Go使用大猩猩
我的結構:
type Interaction struct{
DrugName string `json:"drugName"`
SeverityLevel string `json:"severityLevel"`
Summary string `json:"summary"`
}
type Drug struct {
Name string `json:"drugName"`
Dosages []string `json:"dosages"`
Interactions []Interaction `json:"interactions"`
}
例JSON發送:
{"drugName":"foo","dosages":["dos1"],"interactions":[["advil","high","summaryForAdvil"]]}
REST服務:
func CreateDrug(w http.ResponseWriter, r *http.Request) {
//I verified the received JSON by printing out the bytes:
bytes, _ := ioutil.ReadAll(r.Body)
}
我的目標是在CreateDrug功能做兩個不同的JSONs所以我可以使兩種不同的結構,藥物與互動:
{"drugName":"foo","dosages":["dos1"]}
{"drugName":"advil", "severityLevel":"high", "summary":"summaryForAdvil"}
在圍棋,在這個函數,我如何使用收到的JSON到兩個新JSONs?
非常有趣的想法,我會盡快嘗試和更新,thx! – bmw0128 2014-10-01 02:53:23