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

Parse Error #1229

Closed
louisb0 opened this issue Sep 10, 2018 · 5 comments
Closed

Parse Error #1229

louisb0 opened this issue Sep 10, 2018 · 5 comments
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@louisb0
Copy link

louisb0 commented Sep 10, 2018

I'm parsing JSON sent to a socketing server like so;

        try
 	{
		nlohmann::json json;
		json.parse(request);

		if (json[0].get<std::string>().find("z") != std::string::npos && json[0].get<std::string>().find("L") != std::string::npos &&
			json[0].get<std::string>().find("|") != std::string::npos && json[0].get<std::string>().find("jM") != std::string::npos)
			return true;
	}
	catch (nlohmann::detail::parse_error e)
	{
		c_logger::error(e.what());
		return false;
	}

This is the output from the server after receiving the request;

[~] = {"auth":"p4AzO|L1jMf=","request":"update_ips","ips":{"ip1":"144.12.123.11","ip2":"122.311.33.87","ip3":"91.122.31.633",},"ip_amount":3}
[~] [error] = [json.exception.parse_error.101] parse error at 120: syntax error - unexpected '}'; expected string literal

I really don't see what the issue is, it's probably something really stupid. Help would be appreciated.

@nlohmann
Copy link
Owner

How does the JSON test request looks like? If it is the string in the first line of the output, then the comma after "91.122.31.633" is wrong. This also coincides with column 120.

@louisb0
Copy link
Author

louisb0 commented Sep 10, 2018

My bad, should have removed that last comma. However, I'm now getting;

JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name())));

While in debugging I was unable to see the property type_name, m_type is equal to null. This occurs on this check right here;

if (json["auth"].get<std::string>().find("z") != std::string::npos && json["auth"].get<std::string>().find("L") != std::string::npos &&
			json["auth"].get<std::string>().find("|") != std::string::npos && json["auth"].get<std::string>().find("jM") != std::string::npos)
			return true;

@louisb0
Copy link
Author

louisb0 commented Sep 10, 2018

Never mind, the issue was creating a json object then going json.parse. I presumed this would automatically update the object but it doesn't (I believe), so I had to assign the output of the parse to a variable.

@nlohmann
Copy link
Owner

nlohmann commented Sep 10, 2018

Do you need further assistance?

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Sep 10, 2018
@louisb0
Copy link
Author

louisb0 commented Sep 10, 2018

I'm good, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants