簡體   English   中英

為什么boost :: property_tree :: write_json()將整數值轉換為字符串? 不正確

[英]Why boost::property_tree::write_json() convert integer value to string? It is incorrect.

我的輸入:data.txt

{
        "target_url":"www.19lou.com/forum-1637-thread-10031471311655793-1-1.html",
        "trespassing_field":{
            "ratetype":5,
            "spider":{
                "prod_name":"name",
                "link_src":1 
            }
        }
}

使用代碼:

boost::property_tree::ptree json_tree;
boost::property_tree::read_json("data.txt", json_tree);
std::stringstream json_main_pack;
boost::property_tree::write_json(json_main_pack, json_tree);
LOG(NOTICE) << "json: " << json_main_pack.str();

輸出:

{
    "target_url": "www.19lou.com\/forum-1637-thread-10031471311655793-1-1.html",
    "trespassing_field": {
        "ratetype": "5",
        "spider": {
            "prod_name": "name",
            "link_src": "1"
        }
    }
}

write_json()將整數值轉換為"ratetype":5轉換為"ratetype": "5"這是不正確的。 如何精確轉換?輸入整數值,然后輸出整數值。

此處的Boost.PropertyTree文檔中,看起來所有類型信息都丟失了。 相關報價:

JSON值映射到包含該值的節點。 但是, 所有類型的信息都會丟失。 數字以及文字“ null”,“ true”和“ false”僅映射到其字符串形式。

強調我的。 不幸的是,如果您想保留類型信息,則可能需要使用其他JSON解析器。

您找到其他方法了嗎? @格林

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM