{"action":"created","issue":{"url":"https://api.github.com/repos/byzhang/rapidjson/issues/105","labels_url":"https://api.github.com/repos/byzhang/rapidjson/issues/105/labels{/name}","comments_url":"https://api.github.com/repos/byzhang/rapidjson/issues/105/comments","events_url":"https://api.github.com/repos/byzhang/rapidjson/issues/105/events","html_url":"https://github.com/byzhang/rapidjson/issues/105","id":59729902,"number":105,"title":"Adding elements to an array","user":{"login":"GoogleCodeExporter","id":9614759,"avatar_url":"https://avatars.githubusercontent.com/u/9614759?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCodeExporter","html_url":"https://github.com/GoogleCodeExporter","followers_url":"https://api.github.com/users/GoogleCodeExporter/followers","following_url":"https://api.github.com/users/GoogleCodeExporter/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCodeExporter/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCodeExporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCodeExporter/subscriptions","organizations_url":"https://api.github.com/users/GoogleCodeExporter/orgs","repos_url":"https://api.github.com/users/GoogleCodeExporter/repos","events_url":"https://api.github.com/users/GoogleCodeExporter/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCodeExporter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/byzhang/rapidjson/labels/auto-migrated","name":"auto-migrated","color":"ededed"},{"url":"https://api.github.com/repos/byzhang/rapidjson/labels/Priority-Medium","name":"Priority-Medium","color":"ededed"},{"url":"https://api.github.com/repos/byzhang/rapidjson/labels/Type-Defect","name":"Type-Defect","color":"ededed"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-04T00:14:46Z","updated_at":"2015-03-04T00:14:46Z","closed_at":"2015-03-04T00:14:46Z","body":"```\nHello\n\nMaybe somebody can help me see the problem. I think I'm following the proper \nsteps (I read Issue #59).\n\nI'm trying to add elements to an array, but it stays empty.\n\nHere's my code:\n\n        // Generate output file structure\n        rapidjson::Document jsonDoc;\n        rapidjson::Value newValue;\n\n        jsonDoc.SetObject();\n        jsonDoc.AddMember(\"ArchwaveAES67\", newValue, jsonDoc.GetAllocator());\n        jsonDoc[\"ArchwaveAES67\"].SetObject();\n        rapidjson::Value& aes67 = jsonDoc[\"ArchwaveAES67\"];\n\n        newValue.SetInt(1);\n        aes67.AddMember(\"version\", newValue, jsonDoc.GetAllocator());\n\n        aes67.AddMember(\"devices\", newValue, jsonDoc.GetAllocator());\n        jsonDoc[\"devices\"].SetArray();\n        rapidjson::Value& devices = jsonDoc[\"devices\"];\n\n/*        const RavennaHTTPServers& ravennaHTTPServers = \nm_bonjourBrowser.getRavennaHTTPServers();\n\n        for( RavennaHTTPServers::const_iterator it = ravennaHTTPServers.begin();\n             it != ravennaHTTPServers.end();\n             it++ )\n        {\n            rapidjson::Value newDevice;\n            newDevice.SetObject();\n\n            newValue.SetString( it->second.m_serviceName.c_str() );\n            newDevice.AddMember(\"hostname\", newValue, jsonDoc.GetAllocator());\n\n            sprintf( buff, \"%s:%d\", it->second.m_address.c_str(), it->second.m_port );\n            newValue.SetString( buff );\n            newDevice.AddMember(\"IPaddress\", newValue, jsonDoc.GetAllocator());\n\n            devices.PushBack( newDevice, jsonDoc.GetAllocator() );\n        }\n*/\n\n            rapidjson::Value newDevice;\n            newDevice.SetObject();\n\n            newValue.SetString( \"SomeHost\" );\n            newDevice.AddMember(\"hostname\", newValue, jsonDoc.GetAllocator());\n\n            newValue.SetString( \"12.123.123.12:1562\" );\n            newDevice.AddMember(\"IPaddress\", newValue, jsonDoc.GetAllocator());\n\n            devices.PushBack( newDevice, jsonDoc.GetAllocator() );\n\n\n        // Write output\n        rapidjson::StringBuffer jsonOutput;\n        rapidjson::PrettyWriter< rapidjson::StringBuffer > jsonWriter( jsonOutput );\n\n        jsonDoc.Accept( jsonWriter );\n        printf( \"JSON string: %s\\n\", jsonOutput.GetString() );\n\n\nNote that I commented out the loop, just to make sure that something gets \nadded. The code after the loop tries to add a dummy element to the array.\n\nWhat I get at the output is:\n\n{\n    \"ArchwaveAES67\": {\n        \"version\": 1,\n        \"devices\": null\n    }\n}\n\nInstead of:\n\n{\n    \"ArchwaveAES67\": {\n        \"version\": 1,\n        \"devices\": [\n            \"hostname\": \"SomeHost\",\n            \"IPaddress\": \"12.123.123.12:1562\"\n        ]\n    }\n}\n\nI get no compiler errors nor warnings.\n\nCan anybody help me find the problem? Is this a bug or am I using the library \nwrong?\n\nThanks in advance and kind regards,\nRoberto Barbieri Carrera\n\n```\n\nOriginal issue reported on code.google.com by `rbarbier...@gmail.com` on 21 Mar 2014 at 9:24"},"comment":{"url":"https://api.github.com/repos/byzhang/rapidjson/issues/comments/77070004","html_url":"https://github.com/byzhang/rapidjson/issues/105#issuecomment-77070004","issue_url":"https://api.github.com/repos/byzhang/rapidjson/issues/105","id":77070004,"user":{"login":"GoogleCodeExporter","id":9614759,"avatar_url":"https://avatars.githubusercontent.com/u/9614759?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCodeExporter","html_url":"https://github.com/GoogleCodeExporter","followers_url":"https://api.github.com/users/GoogleCodeExporter/followers","following_url":"https://api.github.com/users/GoogleCodeExporter/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCodeExporter/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCodeExporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCodeExporter/subscriptions","organizations_url":"https://api.github.com/users/GoogleCodeExporter/orgs","repos_url":"https://api.github.com/users/GoogleCodeExporter/repos","events_url":"https://api.github.com/users/GoogleCodeExporter/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCodeExporter/received_events","type":"User","site_admin":false},"created_at":"2015-03-04T00:14:46Z","updated_at":"2015-03-04T00:14:46Z","body":"```\nThis looks wrong:\n   aes67.AddMember(\"devices\", newValue, jsonDoc.GetAllocator());\n   jsonDoc[\"devices\"].SetArray(); // (*)\n   rapidjson::Value& devices = jsonDoc[\"devices\"]; \n\nYou probably meant to use aes67 here instead of jsonDoc:\n   newValue.SetArray();\n   aes67.AddMember(\"devices\", newValue, jsonDoc.GetAllocator());\n   rapidjson::Value& devices = aes67[\"devices\"];\n\nIIRC, requesting the non-existent member \"devices\" in jsonDoc (*) should have \nraised an assertion.  Do you compile with assertions disabled?  This would be a \nbad idea for debugging...\n\nhth,\n  Philipp\n```\n\nOriginal comment by `philipp....@gmail.com` on 21 Mar 2014 at 12:51"}}