Closed DragonOsman closed 5 years ago
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 currency_list.get<std::string>()
do what I want here?
Edit: Okay, using currency_list.get<std::string>()
doesn't help.
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" };
j1
is a string and j2
is an array containing a string.
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:
json jfoo{f};
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 =
.
Related: #2311 #2046
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:
json jfoo{f};
json jfoo = f;
The first of these two is encouraged in recent versions of C++ as it is uniform and safer, especially when using auto
and that's why many developers use it. To have them behave differently is fragile.
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.