2

I am trying to create a json cpp array and populate it with data in a std::vector.

My code looks like this

void
Box_20::BuildCommitUploadPostData(const PartInfoColl& partColl)
{
    Json::Value parts;
    parts["parts"] = Json::arrayValue;

    int idx = 0;

    for (const auto& p : partColl) {

        Json::Value partInfo;

        partInfo["part_id"] = p.partId;
        partInfo["offset"] = p.offset;
        partInfo["size"] = p.size;

        parts[idx]["part"] = partInfo;
        idx++;
    }

    /// do more stuff here
}

However when I run it, it bombs out.

I can;t see what I am doing wrong here.

2
  • "it bombs out" - Care to extend? Commented Jun 1, 2018 at 12:54
  • It crashes the first time it executes parts[idx]["part"] = partInfo; Commented Jun 1, 2018 at 12:56

1 Answer 1

4

This worked.

void DoSOmeJsonStuff(const PartInfoColl& partColl)
{
    Json::Value parts;

    int idx = 0;

    for (const auto& p : partColl) {

        Json::Value partInfo;

        partInfo["part_id"] = p.partId;
        partInfo["offset"] = p.offset;
        partInfo["size"] = p.size;

        parts[idx]["part"] = partInfo;
        idx++;
    }

    Json::Value root;
    root["parts"] = parts;

    /... 
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.