wangxiaowei0303 / rapidjson

Automatically exported from code.google.com/p/rapidjson
MIT License
0 stars 0 forks source link

string类型的第一次字符为\u0000 #81

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
#include <string>
#include <iostream>
#include "./include/rapidjson/document.h"
#include "./include/rapidjson/writer.h"
#include "include/rapidjson/stringbuffer.h"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    rapidjson::StringBuffer            str_buff;
    rapidjson::Document           doc;
    rapidjson::Value              node;
    doc.SetObject();
    node.SetArray();
    for(int i =0; i < 3; i++)
    {
        rapidjson::Value   objs;
        rapidjson::Value   n;
        objs.SetObject();
        string ip = "192.168.0.2";
        n.SetString(ip.data());
        objs.AddMember("ip",n,doc.GetAllocator());
        node.PushBack(objs,doc.GetAllocator());
    }
    doc.AddMember("array",node,doc.GetAllocator());
    rapidjson::Document::AllocatorType allocator;
    rapidjson::Writer<rapidjson::StringBuffer> writer(str_buff, &allocator);
    doc.Accept(writer);

    string output(str_buff.GetString(), str_buff.GetSize());
    cout<<output<<endl;
    return 0;
}

// out put
// 
"{"array":[{"ip":"\u000092.168.0.2"},{"ip":"\u000092.168.0.2"},{"ip":"\u000092.1
68.0.2"}]}"

我想将rapidjson::Documen类型的数据转换为string打印在屏幕上。
但是在这种情况下string类型的字段的第一个字符显示的为\u000
0

Original issue reported on code.google.com by ljia...@gmail.com on 18 Jun 2013 at 10:16

GoogleCodeExporter commented 9 years ago

Original comment by milo...@gmail.com on 19 Jun 2013 at 8:46