You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working with an API that returns floats and ints wrapped in quotes. A typical response is included below. In the examples (and in canonical JSON afaik) ints and floats aren't quote wrapped. I get an "invalid floating point number" error, which I guess is expected given that. Is there a way to add an inner encoder that strips the quotes to get them ready for parsing by the double-conversion lib?
["buy", "1", "3"]
The text was updated successfully, but these errors were encountered:
We were considering adding a codec that would string encode in the way you describe, wrapping a typed codec, i.e., quote(number()). We haven't gotten around doing that yet though. The codec itself would be quite easy to write, first using a string codec to decode the string into a std::string followed by decode by the wrapped codec. This could also be done using the transform() codec, with a bit more manual work.
Neither solution would work in your example, where the quoted values are both numbers and strings. The number() codec will fail to parse "buy" in this case. Instead I'd recommend parsing this array into the following C++ type: std::vector<json::encoded_value>. The encoded_value represents some JSON value, such as "buy" or "3". You can then decode them afterwards using json::decode(...) or json::try_decode(...).
If you know the format of these arrays, for example [<string>, <integer>, <integer>] you can decode the JSON using the tuple() codec. Just make a std::tuple<std::string, int, int> and the default codec should decode it correctly for you.
I'm working with an API that returns floats and ints wrapped in quotes. A typical response is included below. In the examples (and in canonical JSON afaik) ints and floats aren't quote wrapped. I get an
"invalid floating point number"
error, which I guess is expected given that. Is there a way to add an inner encoder that strips the quotes to get them ready for parsing by the double-conversion lib?["buy", "1", "3"]
The text was updated successfully, but these errors were encountered: