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

json::parse() into a vector<string> results in unhandled exception #1587

Closed
Meqolo opened this issue Apr 27, 2019 · 10 comments
Closed

json::parse() into a vector<string> results in unhandled exception #1587

Meqolo opened this issue Apr 27, 2019 · 10 comments

Comments

@Meqolo
Copy link

Meqolo commented Apr 27, 2019

  • What is the issue you have?
    When using json::parse() to parse into a vector, my program crashes with an unhandled exception.

Error: Unhandled exception at 0x767FC6F2 in Project2.exe: Microsoft C++ exception: nlohmann::detail::parse_error at memory location 0x0133E1E8.

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

My code:
std::string strdat = cblox::User::GetFriends(userId); std::vector<string> data = json::parse(strdat);

  • What is the expected behavior?
    It should output the following JSON line by line:
    [{"Id":257718708,"Username":"Hamburgare50","AvatarUri":"http://t7.rbxcdn.com/c3e30a0ce1554cd22a6e0ef438280bd1","AvatarFinal":true,"IsOnline":false},{"Id":24301726,"Username":"Aczero_Ricky","AvatarUri":"http://t5.rbxcdn.com/2293487bb9adcf4b675740e57dc16279","AvatarFinal":true,"IsOnline":false},{"Id":85831697,"Username":"CharlieSBayley","AvatarUri":"http://t2.rbxcdn.com/3cadde4f20421e7afbf9f15ac1ea6f0c","AvatarFinal":true,"IsOnline":false},{"Id":383446385,"Username":"akgtmc","AvatarUri":"http://t6.rbxcdn.com/fd5c89ad7f859a5c59bc31642995d91e","AvatarFinal":true,"IsOnline":false},{"Id":449091095,"Username":"MacaSParker","AvatarUri":"http://t1.rbxcdn.com/1de575ebb080d400bd3ddda2a44a5803","AvatarFinal":true,"IsOnline":false},{"Id":917026880,"Username":"TheRainbowQueen2019","AvatarUri":"http://t1.rbxcdn.com/0fb8f8ed46dc7b5b239e6ab6b4f94ac3","AvatarFinal":true,"IsOnline":false},{"Id":936167157,"Username":"autozz19999","AvatarUri":"http://t6.rbxcdn.com/f33c0a4aade8f944ef60444dbdc76961","AvatarFinal":true,"IsOnline":false},{"Id":508643792,"Username":"SrslyItsJoe","AvatarUri":"http://t3.rbxcdn.com/e85714e9a96e15bd995e5efa25bb03ee","AvatarFinal":true,"IsOnline":false},{"Id":130668355,"Username":"OllieERichardson","AvatarUri":"http://t3.rbxcdn.com/49a233ae435394ca2e86967e12acb5fd","AvatarFinal":true,"IsOnline":true},{"Id":169640794,"Username":"SherylAFitzalan","AvatarUri":"http://t3.rbxcdn.com/c4738efc48824bfc3ddb28f2913f1652","AvatarFinal":true,"IsOnline":false},{"Id":39016790,"Username":"uwaisfreindali","AvatarUri":"http://t7.rbxcdn.com/ff0565e8e81edecbb5d3209a9407fd19","AvatarFinal":true,"IsOnline":false},{"Id":916870937,"Username":"amigobot236","AvatarUri":"http://t2.rbxcdn.com/2ad9b729aa2eed24ef1a37b1c88c90f6","AvatarFinal":true,"IsOnline":false},{"Id":916787871,"Username":"flacal123","AvatarUri":"http://t1.rbxcdn.com/bb0eb89a17864e8520d5f4b5d62d748d","AvatarFinal":true,"IsOnline":false},{"Id":170000078,"Username":"LaceYear","AvatarUri":"http://t3.rbxcdn.com/a6a2f271e266957030bb0aa838f9d656","AvatarFinal":true,"IsOnline":false},{"Id":210501154,"Username":"NaweRBLX","AvatarUri":"http://t5.rbxcdn.com/4a3824bfa6835ccfadeed1d9c5c8ba57","AvatarFinal":true,"IsOnline":false},{"Id":58077857,"Username":"ewanerd","AvatarUri":"http://t2.rbxcdn.com/0de1ced519971055f2c0bcf4d8cbe823","AvatarFinal":true,"IsOnline":false},{"Id":135886259,"Username":"mrstabby7","AvatarUri":"http://t6.rbxcdn.com/4ae565be7b4ef3c555accc8129f92c90","AvatarFinal":true,"IsOnline":false},{"Id":146113463,"Username":"Chile_C","AvatarUri":"http://t4.rbxcdn.com/c19dfec4aa0a04d5c7755c3e91ad84a2","AvatarFinal":true,"IsOnline":false},{"Id":174047682,"Username":"jemilho","AvatarUri":"http://t3.rbxcdn.com/2768f5b7dec4751d7dddc26f6c3ab3a5","AvatarFinal":true,"IsOnline":false},{"Id":96529580,"Username":"MegaXUltra","AvatarUri":"http://t6.rbxcdn.com/6ebeb4dc8e3b17e53a6f545ac2f1280e","AvatarFinal":true,"IsOnline":false}]
  • And what is the actual behavior instead?
    It crashes with the following error: Unhandled exception at 0x767FC6F2 in Project2.exe: Microsoft C++ exception: nlohmann::detail::parse_error at memory location 0x0133E1E8.
  • Which compiler and operating system are you using? Is it a supported compiler?

Win 10 - MSVC 2017

  • Did you use a released version of the library or the version from the develop branch?
    released
  • If you experience a compilation error: can you compile and run the unit tests?
    n/a
@Meqolo
Copy link
Author

Meqolo commented Apr 27, 2019

Occurs at line 2964

				const detail::exception& ex)
			{
				errored = true;
				if (allow_exceptions)
				{
					// determine the proper exception type from the id
					switch ((ex.id / 100) % 100)
					{
					case 1:
						JSON_THROW(*static_cast<const detail::parse_error*>(&ex));
					case 4:
						JSON_THROW(*static_cast<const detail::out_of_range*>(&ex));
						// LCOV_EXCL_START
					case 2:
						JSON_THROW(*static_cast<const detail::invalid_iterator*>(&ex));
					case 3:
						JSON_THROW(*static_cast<const detail::type_error*>(&ex));
					case 5:
						JSON_THROW(*static_cast<const detail::other_error*>(&ex));
					default:
						assert(false);
						// LCOV_EXCL_STOP
					}
				}
				return false;
			}```

@nlohmann
Copy link
Owner

What is the what() output of the exception?

@Meqolo
Copy link
Author

Meqolo commented Apr 27, 2019

What do you mean by the what() output?

@nlohmann
Copy link
Owner

When you catch the nlohmann::�parse_error exception, what is the result of calling what(), see https://nlohmann.github.io/json/classnlohmann_1_1basic__json_af1efc2468e6022be6e35fc2944cabe4d.html#af1efc2468e6022be6e35fc2944cabe4d.

@Meqolo
Copy link
Author

Meqolo commented Apr 27, 2019

I managed to fix it, however I'm getting a different error now

image

@nlohmann
Copy link
Owner

What is the last line in your code before the exception is triggered? It seems to be a conversion to a string type.

@Meqolo
Copy link
Author

Meqolo commented Apr 27, 2019

std::string strdat = cblox::User::GetFriends(userId);

The value the function returns is also a string

@Meqolo
Copy link
Author

Meqolo commented Apr 27, 2019

Ok, I got it to work, but as soon as I try to assign it to a vector array it doesn't like it

@Meqolo
Copy link
Author

Meqolo commented Apr 27, 2019

image

@Meqolo
Copy link
Author

Meqolo commented Apr 27, 2019

Nevermind, got it working now by using json instead of vector.

@Meqolo Meqolo closed this as completed Apr 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants