Example #1
0
static int ProcessEntry(char *outbuf, KeyValueNode *pair, char label) {
    char *json_answer=NULL;
    json_t *root, *results;
	json_error_t error;
    char url[512];
    int entrySize=0, nresults;

    /* cplusplus stuff! */
    try {
        sprintf(url, addressFormat, pair->value);
        json_answer = (char*) DownloadToBuffer(url);
        // process the query result
	    if ((root = json_loads(json_answer, 0, &error)) == NULL) {
		    printf("json error on line %d: %s\n", error.line, error.text);
            // release the response buffer
		    if (json_answer != NULL) free(json_answer);
            return -1;
	    }
        results = json_object_get(root, "results");
        nresults = json_array_size(results);
        for (int i=0; i < nresults; ++i) {
            double lat, lng;
            json_t *result, *geometry, *location;
            result =  json_array_get(results, i);
            location = json_object_get(json_object_get(result, "geometry"), "location");
   
            lat = json_real_value(json_object_get(location, "lat")); 
            lng = json_real_value(json_object_get(location, "lng"));  
      
	        entrySize+=sprintf(outbuf+entrySize, markerFormat, "blue", label, lat, lng);
        }
        if (json_answer != NULL) free(json_answer);
         // release json resources
	    json_decref(root);
        return entrySize;
    }
    catch (...) {
        if (json_answer != NULL) free(json_answer);
        // release json resources
	    json_decref(root);
        return -1;
    }
    
}
Example #2
0
void
Net::DownloadToBufferJob::Run(OperationEnvironment &env)
{
  length = DownloadToBuffer(session, url, buffer, max_length, env);
}