Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'\' char problem in strings #261

Closed
tanisman opened this issue Jun 6, 2016 · 7 comments
Closed

'\' char problem in strings #261

tanisman opened this issue Jun 6, 2016 · 7 comments
Labels
platform: visual studio related to MSVC solution: invalid the issue is not related to the library

Comments

@tanisman
Copy link

tanisman commented Jun 6, 2016

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

@tanisman tanisman changed the title \ char problem '\' char problem in strings Jun 6, 2016
@nlohmann
Copy link
Owner

nlohmann commented Jun 6, 2016

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]
  }
}

@nlohmann nlohmann closed this as completed Jun 6, 2016
@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Jun 6, 2016
@tanisman
Copy link
Author

tanisman commented Jun 6, 2016

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:
image

@nlohmann
Copy link
Owner

nlohmann commented Jun 6, 2016

Can you then please paste the complete JSON as is? The current one begins with "window" and closes with , which both would be noncompliant.

@nlohmann nlohmann reopened this Jun 6, 2016
@nlohmann nlohmann removed the solution: invalid the issue is not related to the library label Jun 6, 2016
@tanisman
Copy link
Author

tanisman commented Jun 6, 2016

{
  "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]
      }
    }
}

@nlohmann
Copy link
Owner

nlohmann commented Jun 7, 2016

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.

@nlohmann nlohmann added the platform: visual studio related to MSVC label Jun 7, 2016
@nlohmann
Copy link
Owner

nlohmann commented Jun 7, 2016

And just to make sure:

  • Are you using the most recent version from the develop branch?
  • Which version of MSVC are you using?

@tanisman
Copy link
Author

tanisman commented Jun 7, 2016

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!

@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Jun 7, 2016
@nlohmann nlohmann closed this as completed Jun 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: visual studio related to MSVC solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants