Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gostnops
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
gostnops
Commits
cf726dca
Commit
cf726dca
authored
Dec 01, 2020
by
李志信
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: check code format
parent
f24f051f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
12 deletions
+13
-12
parser.go
json_struct_parser/parser.go
+12
-11
parser_test.go
json_struct_parser/parser_test.go
+1
-1
user.json
json_struct_parser/user.json
+0
-0
No files found.
json
-struct-
parser/parser.go
→
json
_struct_
parser/parser.go
View file @
cf726dca
...
...
@@ -15,7 +15,7 @@
* limitations under the License.
*/
package
json
_struct_p
arser
package
json
StructP
arser
import
(
"fmt"
...
...
@@ -36,7 +36,7 @@ type jsonStructParser struct {
subObjValueMap
map
[
string
]
reflect
.
Value
}
func
newJ
son
StructParser
()
*
jsonStructParser
{
func
newJ
SON
StructParser
()
*
jsonStructParser
{
return
&
jsonStructParser
{
structFields
:
make
([]
reflect
.
StructField
,
0
),
valueMap
:
make
(
map
[
string
]
string
),
...
...
@@ -45,29 +45,30 @@ func newJsonStructParser() *jsonStructParser {
}
func
init
()
{
defaultJ
sonStructParser
=
newJson
StructParser
()
defaultJ
SONStructParser
=
newJSON
StructParser
()
}
var
defaultJ
son
StructParser
*
jsonStructParser
var
defaultJ
SON
StructParser
*
jsonStructParser
func
JsonFile2Interface
(
path
string
)
(
interface
{},
error
)
{
// JsonFile2Interface parse json @file to interface
func
JsonFile2Interface
(
file
[]
byte
)
(
interface
{},
error
)
{
defer
func
()
{
defaultJ
sonStructParser
=
newJson
StructParser
()
defaultJ
SONStructParser
=
newJSON
StructParser
()
}()
return
defaultJ
sonStructParser
.
Jsonfile2Struct
(
path
)
return
defaultJ
SONStructParser
.
Jsonfile2Struct
(
string
(
file
)
)
}
func
RemoveTargetNameField
(
v
interface
{},
targetName
string
)
interface
{}
{
defer
func
()
{
defaultJ
sonStructParser
=
newJson
StructParser
()
defaultJ
SONStructParser
=
newJSON
StructParser
()
}()
return
defaultJ
son
StructParser
.
RemoveTargetNameField
(
v
,
targetName
)
return
defaultJ
SON
StructParser
.
RemoveTargetNameField
(
v
,
targetName
)
}
func
(
jsp
*
jsonStructParser
)
cb
(
key
[]
byte
,
value
[]
byte
,
dataType
jsonparser
.
ValueType
,
offset
int
)
error
{
switch
dataType
{
case
jsonparser
.
Object
:
// 嵌套子结构
newParser
:=
newJ
son
StructParser
()
newParser
:=
newJ
SON
StructParser
()
subObj
:=
newParser
.
json2Struct
(
value
)
hessian2
.
RegisterPOJOMapping
(
getJavaClassName
(
subObj
),
subObj
)
jsp
.
structFields
=
append
(
jsp
.
structFields
,
reflect
.
StructField
{
...
...
@@ -76,7 +77,7 @@ func (jsp *jsonStructParser) cb(key []byte, value []byte, dataType jsonparser.Va
})
jsp
.
subObjValueMap
[
string
(
key
)]
=
reflect
.
ValueOf
(
subObj
)
case
jsonparser
.
Array
:
//数组结构
newParser
:=
newJ
son
StructParser
()
newParser
:=
newJ
SON
StructParser
()
subObj
:=
newParser
.
json2Struct
(
value
)
hessian2
.
RegisterPOJOMapping
(
getJavaClassName
(
subObj
),
subObj
)
// TODO 目前存在问题
jsp
.
structFields
=
append
(
jsp
.
structFields
,
reflect
.
StructField
{
...
...
json
-struct-
parser/parser_test.go
→
json
_struct_
parser/parser_test.go
View file @
cf726dca
...
...
@@ -15,7 +15,7 @@
* limitations under the License.
*/
package
json
_struct_p
arser
package
json
StructP
arser
import
(
"testing"
...
...
json
-struct-
parser/user.json
→
json
_struct_
parser/user.json
View file @
cf726dca
File moved
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