Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
c5b056f2
Commit
c5b056f2
authored
Oct 05, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update json comments
R=r DELTA=16 (4 added, 2 deleted, 10 changed) OCL=35320 CL=35331
parent
ff97fde2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
12 deletions
+14
-12
src/pkg/json/struct.go
src/pkg/json/struct.go
+14
-12
No files found.
src/pkg/json/struct.go
View file @
c5b056f2
...
...
@@ -179,10 +179,8 @@ func (b *_StructBuilder) Key(k string) Builder {
}
if
v
,
ok
:=
reflect
.
Indirect
(
b
.
val
)
.
(
*
reflect
.
StructValue
);
ok
{
t
:=
v
.
Type
()
.
(
*
reflect
.
StructType
);
if
field
,
ok
:=
t
.
FieldByName
(
k
);
ok
{
return
&
_StructBuilder
{
v
.
FieldByIndex
(
field
.
Index
)
}
}
// Again, case-insensitive.
// Case-insensitive field lookup.
k
=
strings
.
ToLower
(
k
);
for
i
:=
0
;
i
<
t
.
NumField
();
i
++
{
if
strings
.
ToLower
(
t
.
Field
(
i
)
.
Name
)
==
k
{
return
&
_StructBuilder
{
v
.
Field
(
i
)
}
...
...
@@ -194,21 +192,21 @@ func (b *_StructBuilder) Key(k string) Builder {
// Unmarshal parses the JSON syntax string s and fills in
// an arbitrary struct or array pointed at by val.
// It uses the reflect
ion library
to assign to fields
// It uses the reflect
package
to assign to fields
// and arrays embedded in val. Well-formed data that does not fit
// into the struct is discarded.
//
// For example, given the
following
definitions:
// For example, given the
se
definitions:
//
// type Email struct {
//
w
here string;
//
a
ddr string;
//
W
here string;
//
A
ddr string;
// }
//
// type Result struct {
//
n
ame string;
//
p
hone string;
//
emails
[]Email
//
N
ame string;
//
P
hone string;
//
Email
[]Email
// }
//
// var r = Result{ "name", "phone", nil }
...
...
@@ -241,9 +239,13 @@ func (b *_StructBuilder) Key(k string) Builder {
// }
// }
//
// Note that the field r.
p
hone has not been modified and
// Note that the field r.
P
hone has not been modified and
// that the JSON field "address" was discarded.
//
// Because Unmarshal uses the reflect package, it can only
// assign to upper case fields. Unmarshal uses a case-insensitive
// comparison to match JSON field names to struct field names.
//
// On success, Unmarshal returns with ok set to true.
// On a syntax error, it returns with ok set to false and errtok
// set to the offending token.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment