Skip to content

Instantly share code, notes, and snippets.

@wilsonqin
Last active August 29, 2015 14:03
Show Gist options
  • Save wilsonqin/65e1f4e9357713a56af0 to your computer and use it in GitHub Desktop.
Save wilsonqin/65e1f4e9357713a56af0 to your computer and use it in GitHub Desktop.
Weird RapidJson Error
{"receive":1405196259}
{"receive":1405196261}
{"receive":1405196262}
{"receive":1405196281}
{"receive":1405196283}
{"receive":1405196284}
{"receive":1405196284}
{"receive":1405196285}
{"receive":1405196286}
{"receive":1405196286}
{"receive":1405196287}
//rapidjson/example/simpledom/simpledom.cpp`
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include <iostream>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
using namespace rapidjson;
int main() {
char *line = NULL;
size_t line_size = 0;
const char *filepath = "broken_data_book.json";
FILE *file = fopen(filepath, "r");
while(-1 != getline(&line, &line_size, file)){
Document d;
d.Parse(line);
Value& s = d["receive"];
float receive = (float) s.GetDouble();
printf("method 1: %f, method 2: %f\n", receive, (float) d["receive"].GetDouble());
}
return 0;
}
/*
OUTPUT:
method 1: 1405196288.000000, method 2: 1405196288.000000
method 1: 1405196288.000000, method 2: 1405196288.000000
method 1: 1405196288.000000, method 2: 1405196288.000000
method 1: 1405196288.000000, method 2: 1405196288.000000
method 1: 1405196288.000000, method 2: 1405196288.000000
method 1: 1405196288.000000, method 2: 1405196288.000000
method 1: 1405196288.000000, method 2: 1405196288.000000
method 1: 1405196288.000000, method 2: 1405196288.000000
method 1: 1405196288.000000, method 2: 1405196288.000000
method 1: 1405196288.000000, method 2: 1405196288.000000
method 1: 1405196288.000000, method 2: 1405196288.000000
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment