-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Exception "type must be string, but is array" #1730
Comments
So if I do need to turn into a string representation of the current object, in a way that it'll retain all of the key-value pairs it has now, how do I do it? Will doing Edit: Okay, using |
The braces in json currency_list{ get_currency_list() }; seem odd. Can you replace this with json currency_list = get_currency_list(); ? Note braces are interpreted as arrays, so: json j1 = "foo";
json j2 { "foo" };
|
I was just trying to use uniform initialization. Or do you mean braced initialization with this library's objects is always interpreted as initialization for an array? I also need to know how I can check for the existence of a key in a JSON object. Thanks. |
I was hit by this bug as well. Modern C++ practices for uniform initialization do this:
I was debugging this for quite awhile. This is supposed to be the normal, supported way to initialize variables modern C++ (and every variable in my projects of the last few years is initialized this way). This library does require that you not do this and instead use |
Indeed, it's definitely swimming against the tide to alter how the language standard works. The modern language expects these two statements to have the same effect:
The first of these two is encouraged in recent versions of C++ as it is uniform and safer, especially when using |
I agree. But the library is proof that in fact you can implement both syntaxes differently... |
I had to try to find a new currency API because the one I was using most recently (before the one with the list I showed just now) seems to be a deprecated service now. At first I found one that gets its data from the European Central Bank, but it doesn't support all of world countries. I found another one that's free and supports all currencies, but this one doesn't have a way to query it for a list of currencies either. I decided to try and make a JSON object representing a list of currencies on my own. This is the function I did it with:
I tried to use the return value of this function here to send the currency list to the JS code on my app's front end:
But this gave me an error saying:
So how do I fix this error now? Should I turn my current object into a string representation of the same object (if there's a way for it to retain the keys and values it currently has)?
I'm using Windows 10 Single Language Version 1809 Build 17763.678. Compiler is the one for VS2017.
Library version 3.6.1. I don't know if it's a release version or a development branch.
The text was updated successfully, but these errors were encountered: