[英]C++ Curl, how to read return data?
我正在嘗試使用curl和http://www.deanclatworthy.com/imdb從IMDB獲取電影和電視節目信息。 我正在使用http://curl.haxx.se/libcurl/c/simple.html中的simple.c示例
cout << "Type a movie name: " << endl;
getline(cin, searchTerm);
replace(searchTerm.begin(), searchTerm.end(), ' ', '+');
CURL *curl;
CURLcode res;
string temp;
temp = "http://www.deanclatworthy.com/imdb/?q=" + searchTerm;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, temp.c_str());
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
/* Check for errors */
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
/* always cleanup */
curl_easy_cleanup(curl);
}
這是我的輸出,如果我搜索黑暗騎士崛起:
輸入電影名稱: The Dark Knight Rises {“imdbid”:“tt1345836”,“imdburl”:“http://www.imdb.com/title/tt1345836/”,“genres”:“Action,Crime,Thriller” “語言”: “英語”, “國”: “美國,英國”, “票”: “390735”, “STV”:0, “系列”:0, “評級”: “8.8”, “運行” :“165分鍾”,“標題”:“黑暗騎士崛起”,“年”:“2012”,“usascreens”:4404,“ukscreens”:0}
我的問題是,我希望將帶有信息的文本放入一個數組中,這樣我就能把它弄好,例如
movieInto[14] = *array*
然后我可以調用數組的不同部分,如果我想要標題,評級,年份等。 它已經被格式化為一個數組,但我無法弄清楚要調用什么來進入。
希望這里聰明的頭腦可以幫助我=)
該數據看起來像JSON,因此您應該使用JSON解析器 - 有很多選項 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.