'I want to extract specific values from a string in C++

I have a program that returns a long string from a curl request, the code is as follows:

#include <iostream>
#include <string>
#include <curl/curl.h>


static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userp)
{
    ((std::string*)userp)->append((char*)contents, size * nmemb);
    return size * nmemb;
}

int main(void)
{
    std::string s;
    CURL* curl;
    CURLcode res;
    curl = curl_easy_init();
    if (curl) {
        curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
        curl_easy_setopt(curl, CURLOPT_URL, "www.ecobliss.co.za/run_student_query.php?query=Select%20*%20FROM%20data%20WHERE%20ID%20%3C%2030");
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
        std::cout << s << std::endl;
        struct curl_slist* headers = NULL;
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        res = curl_easy_perform(curl);
    }
    curl_easy_cleanup(curl);

    //std::cout << s;

    std::string arr[10000];
    int i = s.find_first_of("ID");
    //std::cout << i<<std::endl;
    int ic = 0;
    while (i>0) {
        std::cout << i;
        if (i > 0) {
        arr[ic] = s.substr(i, i + 6);
        s.erase(i,i+1);
        int i = s.find_first_of("ID");
        std::cout << i;
        }
        if (i < 0) {
            break;
        }
         ic++;

    }

    for (ic = 0; ic < std::size(arr); ic++) {
        std::cout << arr[ic];
    }
    return 0;
}

the output of the request in postman is:


<p>Results from your query:</p>
<br>{"ID":"26","datetime":"2022-03-13 03:21:07","temperature":"25.3","humidity":"80.9","pressure":"1020.2"}<br>{"ID":"27","datetime":"2022-03-13 05:12:47","temperature":"24.8","humidity":"82.1","pressure":"1020.5"}<br>{"ID":"28","datetime":"2022-03-13 05:29:05","temperature":"24.9","humidity":"83.6","pressure":"1020.5"}<br>{"ID":"29","datetime":"2022-03-13 05:29:07","temperature":"24.9","humidity":"83.8","pressure":"1020.5"}

I have tried to use string handling and extract the value the ID part holds, but it does not work at all, can someone please help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source