Closed tanisman closed 8 years ago
On first sight, there are too many backslashes: there should be two instead of three, because \i
and \s
are not allowed according to RFC 7159, Section 7. The correct JSON would be:
{
"window": {
"texture": "interface\\ifcommon\\slibifwnd.ddj",
"width": 330,
"height": 366,
"position": [0, 0],
"rect": [0, 0, 330, 366],
"moveable": true,
"moverect": [0, 0, 330, 30]
}
}
it has 2 backslashes but my web browser showed one backslash after posting that, than I have edited my post.Here is picture of json:
Can you then please paste the complete JSON as is? The current one begins with "window"
and closes with ,
which both would be noncompliant.
{
"window": {
"texture": "interface\\ifcommon\\slibifwnd.ddj",
"width":330,
"height":366,
"position": [0, 0],
"rect": [0, 0, 330, 366],
"moveable": true,
"moverect": [0, 0, 330, 30]
},
"elements": {
"count":2,
"1": {
"class": "button",
"textures": [
"interface\\ifcommon\\com_button.ddj",
"interface\\ifcommon\\com_button_focus.ddj",
"interface\\ifcommon\\com_button_press.ddj",
"interface\\ifcommon\\com_button_disable.ddj"
],
"width": 76,
"height": 24,
"text": "Button1",
"disabled": false,
"position": [150, 50],
"rect": [0, 0, 76, 24]
},
"2": {
"class": "edit",
"textures": [
"interface\\ifcommon\\slib_editbox.ddj"
],
"width": 107,
"height": 21,
"text": "EditBox1",
"disabled": false,
"position": [30, 50],
"rect": [5, 0, 102, 19]
}
}
}
Thanks. This file is valid JSON, and I can parse it without problems with
#include <json.hpp>
#include <fstream>
using nlohmann::json;
int main()
{
// just parse the string
json s = R"("interface\\ifcommon\\slibifwnd.ddj")"_json;
std::cout << std::setw(2) << s << std::endl;
// parse the whole file
std::ifstream f("issue261.json");
json j;
j << f;
std::cout << std::setw(2) << j << std::endl;
}
Could you please try this code? Especially, parsing just the string would be interesting.
And just to make sure:
develop
branch?I figured out the problem;
there is no problem when I use R prefix
json s = R"("interface\\ifcommon\\slibifwnd.ddj")"_json;
std::cout << std::setw(2) << s << std::endl;
but the problem is backslashes, json required format:
path\\to\\directory
as you know its presented in C as
path\\\\to\\\\directory
I was trying to load from a variable not a file that was my mistake
Thanks for your care!
I am trying to parse this json:
"window": { "texture": "interface\ifcommon\slibifwnd.ddj", "width":330, "height":366, "position": [0, 0], "rect": [0, 0, 330, 366], "moveable": true, "moverect": [0, 0, 330, 30] },
but parser gives me unexpected \ error for string.
IDE: Visual Studio 2015