Commit f6240e14 by OFFICE\dingda.li

1.补传过滤空json-object

parent fb53ac55
...@@ -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);
......
...@@ -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>("{}");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment