我想從一個JSON對象中取一個字符串,我知道它代表了一個十進制數,並將它分配給C++中的一個double。jsoncpp:將字符串轉換爲雙倍
人們會預計asDouble()
會完成這項工作,但事實並非如此。例如,如果我們(在C++ 11)的陣列["0.4983", "4387"]
坐在變量Json::Value arr
,做
double x = arr[0].asDouble()
拋出一個異常Value is not convertible to double.
什麼是這樣做的推薦的方法?
可能的複製。 com/questions/4754011/c-string-to-double-conversion) – Scheff
當你這樣嘗試時會發生什麼:'Json :: Value val = arr [0]; double x = val.asDouble();' –
'arr.isArray()'的返回值是什麼? –