猿问

Gorethink 插入问题

var data = map[string]interface{}{

    "json_received": [

        {

        "ezpOrderId":  "ezp_123",

        "firstName":  "Vasanth",

        "lastName":  "K",

        "orderDesc":  "Sample"

        }

    ] 

    "created_on":  "03-22-2015",

    "status":  "1"

}



result, err := r.Table("order_json").Insert(data).RunWrite(session)

当我尝试运行这个程序时,我在“json_received”:[ 行之后收到“缺少操作数”的错误消息。


请帮助我通过 go 编程在 rethink db 中插入数据变量..


潇湘沐
浏览 223回答 2
2回答

撒科打诨

Go 不支持像您尝试做的 json 文字。这是一个固定版本(在 Play 上)。请注意,对于所有子结构,您必须在创建时声明类型。你试图让 json_recieved 成为一个 json 对象列表,所以我使用了[]map[string]interface{}.而且,正如其他人所指出的,多行映射/列表文字必须在每行后有一个逗号,如:orderDesc, status。包主import "fmt"func main() {    var data = map[string]interface{}{        "json_received": []map[string]interface{}{            {                "ezpOrderId": "ezp_123",                "firstName":  "Vasanth",                "lastName":   "K",                "orderDesc":  "Sample",            },        },        "created_on": "03-22-2015",        "status":     "1",    }    fmt.Printf("%#v\n", data)    //result, err := r.Table("order_json").Insert(data).RunWrite(session)}

噜噜哒

您在 json_received 数组后缺少逗号"json_received": [&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; "ezpOrderId":&nbsp; "ezp_123",&nbsp; &nbsp; &nbsp; &nbsp; "firstName":&nbsp; "Vasanth",&nbsp; &nbsp; &nbsp; &nbsp; "lastName":&nbsp; "K",&nbsp; &nbsp; &nbsp; &nbsp; "orderDesc":&nbsp; "Sample"&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; ] , //<--
随时随地看视频慕课网APP

相关分类

Go
我要回答