Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fmcoupon-linux
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李定达
fmcoupon-linux
Commits
f6240e14
Commit
f6240e14
authored
Aug 04, 2020
by
OFFICE\dingda.li
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.补传过滤空json-object
parent
fb53ac55
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
4 deletions
+44
-4
fm_xmltojson.hpp
+8
-4
main.cpp
+36
-0
No files found.
fm_xmltojson.hpp
View file @
f6240e14
...
@@ -802,7 +802,8 @@ public:
...
@@ -802,7 +802,8 @@ public:
{
{
InsertValueToJson
(
attrs
,
desdoc
,
objectvalue
,
sval
,
sparentvalue
);
InsertValueToJson
(
attrs
,
desdoc
,
objectvalue
,
sval
,
sparentvalue
);
}
}
arrayvalue
.
PushBack
(
objectvalue
,
desdoc
.
GetAllocator
());
if
(
objectvalue
.
GetObject
().
MemberCount
()
>
0
)
arrayvalue
.
PushBack
(
objectvalue
,
desdoc
.
GetAllocator
());
}
}
if
(
dval
.
HasMember
(
pkey
))
if
(
dval
.
HasMember
(
pkey
))
...
@@ -829,7 +830,8 @@ public:
...
@@ -829,7 +830,8 @@ public:
{
{
InsertValueToJson
(
attr
,
desdoc
,
objectvalue
,
sval
,
sparentvalue
);
InsertValueToJson
(
attr
,
desdoc
,
objectvalue
,
sval
,
sparentvalue
);
}
}
arrayvalue
.
PushBack
(
objectvalue
,
desdoc
.
GetAllocator
());
if
(
objectvalue
.
GetObject
().
MemberCount
()
>
0
)
arrayvalue
.
PushBack
(
objectvalue
,
desdoc
.
GetAllocator
());
if
(
dval
.
HasMember
(
pkey
))
if
(
dval
.
HasMember
(
pkey
))
dval
.
RemoveMember
(
pkey
);
dval
.
RemoveMember
(
pkey
);
...
@@ -992,7 +994,8 @@ public:
...
@@ -992,7 +994,8 @@ public:
{
{
InsertValueToJson
(
attr
,
desdoc
,
objectvalue
,
sval
,
valus
.
GetArray
()[
i
],
string
(
node
->
first_attribute
(
XML_ATT_OKEY
)
->
value
()));
InsertValueToJson
(
attr
,
desdoc
,
objectvalue
,
sval
,
valus
.
GetArray
()[
i
],
string
(
node
->
first_attribute
(
XML_ATT_OKEY
)
->
value
()));
}
}
arrayvalue
.
PushBack
(
objectvalue
,
desdoc
.
GetAllocator
());
if
(
objectvalue
.
GetObject
().
MemberCount
()
>
0
)
arrayvalue
.
PushBack
(
objectvalue
,
desdoc
.
GetAllocator
());
}
}
if
(
dval
.
HasMember
(
pkey
))
if
(
dval
.
HasMember
(
pkey
))
...
@@ -1020,7 +1023,8 @@ public:
...
@@ -1020,7 +1023,8 @@ public:
{
{
InsertValueToJson
(
attr
,
desdoc
,
objectvalue
,
sval
,
valus
,
string
(
node
->
first_attribute
(
XML_ATT_OKEY
)
->
value
()));
InsertValueToJson
(
attr
,
desdoc
,
objectvalue
,
sval
,
valus
,
string
(
node
->
first_attribute
(
XML_ATT_OKEY
)
->
value
()));
}
}
arrayvalue
.
PushBack
(
objectvalue
,
desdoc
.
GetAllocator
());
if
(
objectvalue
.
GetObject
().
MemberCount
()
>
0
)
arrayvalue
.
PushBack
(
objectvalue
,
desdoc
.
GetAllocator
());
if
(
dval
.
HasMember
(
pkey
))
if
(
dval
.
HasMember
(
pkey
))
dval
.
RemoveMember
(
pkey
);
dval
.
RemoveMember
(
pkey
);
...
...
main.cpp
View file @
f6240e14
...
@@ -66,6 +66,7 @@ int main(int argc, char *argv[])
...
@@ -66,6 +66,7 @@ int main(int argc, char *argv[])
#include <rapidjson/filewritestream.h>
#include <rapidjson/filewritestream.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/stringbuffer.h>
#include <rapidjson/writer.h>
#include <rapidjson/writer.h>
#include "fm_xmltojson.hpp"
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
...
@@ -85,6 +86,41 @@ int main(int argc, char *argv[])
...
@@ -85,6 +86,41 @@ int main(int argc, char *argv[])
logger
.
addDestination
(
consleDest
);
logger
.
addDestination
(
consleDest
);
{
{
std
::
string
strIn
=
std
::
string
(
"{
\"
business_date
\"
:
\"
20200803
\"
,
\"
operator_id
\"
:
\"
admin
\"
,
\"
pos_id
\"
:
\"
CN0101000
\"
,
\"
store_id
\"
:
\"
CN0101000
\"
,
\"
partner_id
\"
:1400,
\"
fm_cmd
\"
:10032,
\"
trans_id
\"
:
\"
201802020001
\"
,
\"
order_amount
\"
:13600,
\"
coupon
\"
:
\"
943093287143765437
\"
,
\"
products
\"
:[{
\"
seq
\"
:
\"
1
\"
,
\"
pid
\"
:
\"
XXXXXXXXX
\"
,
\"
name
\"
:
\"
商品A
\"
,
\"
price
\"
:5100,
\"
qty
\"
:2,
\"
sub_items
\"
:[{
\"
name
\"
:
\"
珍珠
\"
,
\"
price
\"
:100,
\"
qty
\"
:1},{
\"
name
\"
:
\"
椰果
\"
,
\"
price
\"
:100,
\"
qty
\"
:1}]},{
\"
seq
\"
:
\"
2
\"
,
\"
pid
\"
:
\"
YYYYYYYYY
\"
,
\"
name
\"
:
\"
商品B
\"
,
\"
price
\"
:3000,
\"
qty
\"
:1}]}"
);
std
::
string
strOut
;
std
::
string
key
;
std
::
string
value
;
std
::
string
error
;
if
(
!
fm_xmltojson
::
JsonConvertFront
(
strIn
,
strOut
,
key
,
value
,
error
))
{
QLOG_ERROR
()
<<
"#JsonConvertPost failed"
<<
error
.
data
();
}
QLOG_INFO
()
<<
"#strOut"
<<
strOut
.
data
();
QLOG_INFO
()
<<
"#key"
<<
key
.
data
();
QLOG_INFO
()
<<
"#value"
<<
value
.
data
();
QLOG_INFO
()
<<
"#error"
<<
error
.
data
();
}
{
std
::
string
strIn
=
std
::
string
(
"{
\"
couponOrderInfo
\"
:{
\"
originalPrice
\"
:1100.00,
\"
salePrice
\"
:800.00},
\"
ebCode
\"
:
\"
0000000973
\"
,
\"
ebName
\"
:
\"
A11
\"
,
\"
orderInfo
\"
:{
\"
activeCode
\"
:
\"
P140020200703102620
\"
,
\"
activeName
\"
:
\"
zznc
\"
,
\"
amountPaid
\"
:0,
\"
discountOrderProducts
\"
:[{
\"
lineNumber
\"
:1,
\"
merchantDiscountPrice
\"
:400,
\"
otherDiscountPrice
\"
:0,
\"
platformDiscountPrice
\"
:800,
\"
productNumber
\"
:
\"
CNAAAACAA
\"
,
\"
quantity
\"
:1}],
\"
totalMerchantDiscount
\"
:400,
\"
totalOtherDiscount
\"
:0,
\"
totalPlatformDiscount
\"
:800,
\"
voucherType
\"
:0},
\"
originResultCode
\"
:
\"
1
\"
,
\"
productLimit
\"
:0,
\"
requestAccount
\"
:
\"
1400
\"
,
\"
resultCode
\"
:
\"
69
\"
,
\"
signParam
\"
:
\"
3440EAE916DFA142113E1FCF19700355
\"
,
\"
storeNumber
\"
:
\"
CN0101000
\"
,
\"
transId
\"
:
\"
202008030002002
\"
,
\"
voucherNumber
\"
:
\"
86613483097985697640
\"
}"
);
std
::
string
strOut
;
std
::
string
key
=
std
::
string
(
"fm_cmd"
);
std
::
string
value
=
std
::
string
(
"10039"
);
std
::
string
error
;
if
(
!
fm_xmltojson
::
JsonConvertPost
(
strIn
,
strOut
,
key
,
value
,
error
))
{
QLOG_ERROR
()
<<
"JsonConvertPost failed"
<<
error
.
data
();
}
QLOG_INFO
()
<<
"strOut"
<<
strOut
.
data
();
}
{
rapidjson
::
Document
s
;
rapidjson
::
Document
s
;
s
.
Parse
<
0
>
(
"{}"
);
s
.
Parse
<
0
>
(
"{}"
);
...
...
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