本文整理汇总了Golang中github.com/pquerna/ffjson/tests/types/ff.Everything.UnmarshalJSON方法的典型用法代码示例。如果您正苦于以下问题:Golang Everything.UnmarshalJSON方法的具体用法?Golang Everything.UnmarshalJSON怎么用?Golang Everything.UnmarshalJSON使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pquerna/ffjson/tests/types/ff.Everything
的用法示例。
在下文中一共展示了Everything.UnmarshalJSON方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUnmarshalEmpty
func TestUnmarshalEmpty(t *testing.T) {
record := ff.Everything{}
err := record.UnmarshalJSON([]byte(`{}`))
if err != nil {
t.Fatalf("UnmarshalJSON: %v", err)
}
}
示例2: TestUnmarshalNullPointer
func TestUnmarshalNullPointer(t *testing.T) {
record := ff.Everything{}
err := record.UnmarshalJSON([]byte(`{"FooStruct": null,"Something":99}`))
if err != nil {
t.Fatalf("UnmarshalJSON: %v", err)
}
if record.FooStruct != nil {
t.Fatalf("record.Something decoding problem, expected: nil got: %v", record.FooStruct)
}
}
示例3: TestUnmarshalToReusedObject
func TestUnmarshalToReusedObject(t *testing.T) {
JSONParts := []string{
`"Bool":true`,
`"Int":1`,
`"Int8": 2`,
`"Int16": 3`,
`"Int32": -4`,
`"Int64": 57`,
`"Uint": 100`,
`"Uint8": 101`,
`"Uint16": 102`,
`"Uint32": 50`,
`"Uint64": 103`,
`"Uintptr": 104`,
`"Float32": 3.14`,
`"Float64": 3.15`,
`"Array": [1,2,3]`,
`"Map": {"bar": 2,"foo": 1}`,
`"String": "snowman☃\uD801\uDC37"`,
`"StringPointer": "pointed snowman☃\uD801\uDC37"`,
`"Int64Pointer": 44`,
`"FooStruct": {"Bar": 1}`,
`"MapMap": {"a0": {"b0":"foo"}, "a1":{"a2":"bar"}}`,
`"MapArraySlice": {"foo":[[1,2,3],[4,5,6],[7]], "bar": [[1,2,3,4],[5,6,7]]}`,
`"Something": 99`,
}
JSONWhole := "{" + strings.Join(JSONParts, ",") + "}"
var record ff.Everything
if err := record.UnmarshalJSON([]byte(JSONWhole)); err != nil {
t.Fatalf("UnmarshalJSON: %v", err)
}
for _, part := range JSONParts {
reuseRecord := record
if err := reuseRecord.UnmarshalJSON([]byte("{" + part + "}")); err != nil {
t.Fatalf("UnmarshalJSON: %v", err)
}
var emptyRecord ff.Everything
if err := emptyRecord.UnmarshalJSON([]byte("{" + part + "}")); err != nil {
t.Fatalf("UnmarshalJSON: %v", err)
}
if !reflect.DeepEqual(reuseRecord, emptyRecord) {
t.Errorf("%#v should be equal to %#v", reuseRecord, emptyRecord)
}
}
}
示例4: TestUnmarshalFull
func TestUnmarshalFull(t *testing.T) {
record := ff.Everything{}
// TODO(pquerna): add unicode snowman
// TODO(pquerna): handle Bar subtype
err := record.UnmarshalJSON([]byte(everythingJson))
if err != nil {
t.Fatalf("UnmarshalJSON: %v", err)
}
expect := "snowman☃𐐷"
if record.String != expect {
t.Fatalf("record.String decoding problem, expected: %v got: %v", expect, record.String)
}
if record.Something != 99 {
t.Fatalf("record.Something decoding problem, expected: 99 got: %v", record.Something)
}
}