本文整理匯總了Golang中github.com/bitly/go-simplejson.Json.Array方法的典型用法代碼示例。如果您正苦於以下問題:Golang Json.Array方法的具體用法?Golang Json.Array怎麽用?Golang Json.Array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/bitly/go-simplejson.Json
的用法示例。
在下文中一共展示了Json.Array方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: sumJSON
// Handles returning a sum for a *Json.
func sumJSON(json *simplejson.Json, ignoreRed bool) int {
slice, err := json.Array()
if err != nil {
panic(err)
}
return sumSlice(slice, ignoreRed)
}
示例2: createTableStatement
func createTableStatement(tableName *string, columnsJson *simplejson.Json, uniqueColumns *simplejson.Json, primaryKeyColumns *simplejson.Json) string {
var buffer bytes.Buffer
buffer.WriteString("CREATE TABLE ")
buffer.WriteString(*tableName)
buffer.WriteString(" (\n")
columnsArry, err := columnsJson.Array()
if err != nil {
reportError("Couldn't parse columns json: ", err)
}
for i, _ := range columnsArry {
if i != 0 {
buffer.WriteString(",\n")
}
columnSchema := columnsJson.GetIndex(i)
columnName, err := columnSchema.Get("name").String()
if err != nil {
reportError("Couldn't parse column name for table json: ", err)
}
columnType, err := columnSchema.Get("type").String()
if err != nil {
reportError("Couldn't parse column type for table json: ", err)
}
buffer.WriteString(columnName)
buffer.WriteString(" ")
buffer.WriteString(columnType)
if columnUnique, err := columnSchema.Get("unique").Bool(); err == nil && columnUnique {
buffer.WriteString(" UNIQUE")
}
if columnNull, err := columnSchema.Get("null").Bool(); err == nil && !columnNull {
buffer.WriteString(" NOT NULL")
}
}
uniqueColumnsArry, err := uniqueColumns.Array()
if err == nil && len(uniqueColumnsArry) > 0 { // error would mean there weren't any uniqueColmns defined
buffer.WriteString(",\nUNIQUE (")
for i, _ := range uniqueColumnsArry {
if i != 0 {
buffer.WriteString(", ")
}
uniqueColumnName, err := uniqueColumns.GetIndex(i).String()
if err != nil {
reportError("Couldn't parse unique column name for table json: ", err)
}
buffer.WriteString(uniqueColumnName)
}
buffer.WriteString(")")
}
primaryKeyColumnsArry, err := primaryKeyColumns.Array()
if err == nil && len(primaryKeyColumnsArry) > 0 { // error would mean there weren't any uniqueColmns defined
buffer.WriteString(",\nUNIQUE (")
for i, _ := range primaryKeyColumnsArry {
if i != 0 {
buffer.WriteString(", ")
}
primaryKeyColumnName, err := primaryKeyColumns.GetIndex(i).String()
if err != nil {
reportError("Couldn't parse primary key column name for table json: ", err)
}
buffer.WriteString(primaryKeyColumnName)
}
buffer.WriteString(")")
}
buffer.WriteString("\n);")
return buffer.String()
}