Question

I am trying to use curl and http://www.deanclatworthy.com/imdb to get movie and tv show information from IMDB. I am using the simple.c example from http://curl.haxx.se/libcurl/c/simple.html

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);
}

This is my output, if i search for The Dark Knight Rises:

Type a movie name: The Dark Knight Rises {"imdbid":"tt1345836","imdburl":"http://www.imdb.com/title/tt1345836/","genres":"Action,Crime,Thriller","languages":"English","country":"USA,UK","votes":"390735","stv":0,"series":0,"rating":"8.8","runtime":"165min","title":"The Dark Knight Rises","year":"2012","usascreens":4404,"ukscreens":0}

My problem is that i want the text that is returned, with the information, to be put into an array so i can get it up nice, e.g.

movieInto[14] = *array*

and then i can call the different parts of the array if i want to title, rating, year and so on. It is already formatted as an array but i cant figure out what to call to get the into.

Hope the bright minds in here can help me out =)

Was it helpful?

Solution

That data looks like JSON, so you should use a JSON parser -- there are many options.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top