1

I am trying to make a program that will use Json from a website and I seem to be having a problem with this:

std::ifstream ifile("json.txt");
Json::Reader reader;
Json::Value root;
if (ifile != NULL && reader.parse(ifile, root)) {
    const Json::Value arrayDest = root["dest"];
    for (unsigned int i = 0; i < arrayDest.size(); i++) {
        if (!arrayDest[i].isMember("name"))
        continue;
        std::string out;
        out = arrayDest[i]["name"].asString();
        std::cout << out << "\n";
    }
}

I have narrow down the issue to the line Json::Reader reader;

and it giving me an error:

Debug assertion... _pFirstBlock == pHead

I'm using jsoncpp

yizzlez
  • 8,757
  • 4
  • 29
  • 44
Mocolicious
  • 315
  • 1
  • 10

1 Answers1

1

This is not a JsonCpp error; pHead appears nowhere in the JsonCpp source code. From a brief Google search, it looks like an error reported within Microsoft Visual C++'s runtime libraries, triggered by a mismatch between where memory is allocated and where it's freed when DLLs are in use, or between which versions of the C runtime are being used, or between how the C runtime is being linked.

Community
  • 1
  • 1
Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
  • Why does it hate the line "Json:Reader reader"? I'm not sure what DLLs would be associated with that – Mocolicious Jun 15 '14 at 20:55
  • @Mocolicious - You have the C/C++ runtime library (which, depending on project settings, may or may not be a DLL), the JsonCpp library (which may or may not be a DLL and which depends on the C/C++ runtime library), and your own code (which depends on both JsonCpp and the C/C++ runtime). If your code and JsonCpp, for example, disagree on how they should use the C/C++ runtime, then chaos ensues. I don't have much personal experience with Visual C++, but a Google search (or that linked StackOverflow answer) should have plenty of specifics for how to fix it. – Josh Kelley Jun 15 '14 at 21:00
  • yeah, thanks. I had found that link when I searched it originally but I'm still confused where I go from here. – Mocolicious Jun 15 '14 at 21:13
  • @Mocolicious - Like I said, I don't have much recent MSVC experience, but try verifying that either everything is statically linked or that both your project and JsonCpp are linking to the MSVC runtime as a DLL. Verify that everything is using the same settings (debug versus release). Verify that everything using the same version of MSVC. The linked question, and some of the discussions linked from there, give more details on specific settings to check. – Josh Kelley Jun 15 '14 at 21:23
  • @Mocolicious - If all else fails, directly include the JsonCpp source files in your project, instead of linking it as a library. That should bypass all of this. – Josh Kelley Jun 15 '14 at 21:23
  • thanks @Josh Kelley That gives me a good push in the right direction. – Mocolicious Jun 15 '14 at 21:25
  • I tried including all the source files in my project and still no joy. – Mocolicious Jun 30 '14 at 18:04
  • @Mocolicious - Not sure what else to tell you. Try creating a minimal project with just JsonCpp files and an int main() that allocates a Json::Reader and Json::Value, and if you're still having problems, try posting a link to that or steps to recreate it. (I'm not sure where the best place to post it is; SO probably frowns on posting complete Visual C++ solutions, but I'm certain that the problem is in your project / solution settings.) – Josh Kelley Jun 30 '14 at 18:48