我使用從我的.get(電影)函數接收的json值來獲取我的json電影對象中每個鍵的值。我試圖將它輸出到fltk GUI中的字段中,該字段需要是const char *類型。但是,我得到了奇怪的字符,而不是我的價值觀。這裏有一個明顯的問題嗎?從json C++輸出獲取字段中的奇怪字符
Json::Value result = m.get(movie);
std::cout << result << endl;
const char *released = result.get("Released", "NULL").asCString();
releasedInput->value(released);
const char *rated = result.get("Rated", "NULL").asCString();
ratedInput->value(rated);
Json::Value actors = result.operator[]("Actors");
const char *plot = result.get("Plot", "NULL").asCString();
plotMLIn->value(plot);
const char *runtime = result.get("Runtime", "NULL").asCString();
runtimeInput->value(runtime);
Json::Value genre = result.operator[]("Genre");
const char *filename = result.get("Filename", "NULL").asCString();
filenameInput->value(filename);
const char *title = result.get("Title", "NULL").asCString();
titleInput->value(title)
我在我的函數中只粘貼了相關行。如果需要更多澄清,我很樂意提供。
您是否嘗試過調試代碼?嘗試在調試器中逐行執行代碼,同時監視變量及其值?什麼字符串錯了? *他們怎麼錯了?你期望什麼文字,你實際上得到了什麼? –
對於#1,當我使用std :: string時,我得到了錯誤消息,他們必須是類型const char *,所以我改變了它。對於#2,這是因爲我只是在學習這一點,並且從文檔看,這看起來是該做的事情。 – Kendra
哦,你爲什麼要顯式調用'operator []'作爲一個函數?爲什麼不'結果[ 「演員」]'? –