samedi 19 décembre 2020

Rapidjson returning wrong data

The json I receive:

{
  "status": "success",
  "data": {
    "user_id": "acv",
    "user_type": "individual",
    "email": "abc@xyz.com",
    "user_name": "xyz",
    "user_shortname": "xx",
    "broker": "zzzz",
    "exchanges": [
      "aaa",
      "cvv",
      "bbb",
      "sss",
      "MF",
      "eee"
    ],
    "products": [
      "CNC",
      "NRML",
      "MIS",
      "BO",
      "CO"
    ],
    "order_types": [
      "MARKET",
      "LIMIT",
      "SL",
      "SL-M"
    ],
    "avatar_url": "",
    "meta": {
      "demat_consent": "consent"
    }
  }
}

I have a function that parses received json: (rj is nothing but a namespace alias declared like using rj=rapidjson;)

rj::Value& parser(...){
    rj::Document data;

    data.Parse("data received passed as const char*");

    //------can access correct email string here------
    std::string debugstr = data["data"].GetObject()["email"].GetString();


    return data["data"];

  }
   

I use it like:

void func1(){
    rj::Value::Object res = parser().GetObject();
 
    //-----this string for some reason is "\003"------
    std::string debugstr = res["email"].GetString();
}

Why is this happening? I've ran this multiple times. I'm on Linux using latest rapidjson.

Similar to the email field, I cannot access other values correctly as well. Only one (broker) is correct while others are either empty strings or random garbage.

Aucun commentaire:

Enregistrer un commentaire