}
// First, tag match
tagName, _ := parseTag(tag)
- if tagName == key {
- f = sf
- ok = true
- break // no better match possible
+ if tagName != "" {
+ if tagName == key {
+ f = sf
+ ok = true
+ break // no better match possible
+ }
+ // There was a tag, but it didn't match.
+ // Ignore field names.
+ continue
}
// Second, exact field name match
if sf.Name == key {
Z int `json:"-"`
}
+type U struct {
+ Alphabet string `json:"alpha"`
+}
+
type tx struct {
x int
}
// Z has a "-" tag.
{`{"Y": 1, "Z": 2}`, new(T), T{Y: 1}, nil},
+ {`{"alpha": "abc", "alphabet": "xyz"}`, new(U), U{Alphabet: "abc"}, nil},
+ {`{"alpha": "abc"}`, new(U), U{Alphabet: "abc"}, nil},
+ {`{"alphabet": "xyz"}`, new(U), U{}, nil},
+
// syntax errors
{`{"X": "foo", "Y"}`, nil, nil, &SyntaxError{"invalid character '}' after object key", 17}},
{`[1, 2, 3+]`, nil, nil, &SyntaxError{"invalid character '+' after array element", 9}},