Datos binarios JSONCPP
Estoy tratando de usar JSON cpp con VS2008.
¿Alguien puede decirme si es posible empaquetar datos binarios en formato JSON? Estoy leyendo un archivo de imagen enchar* buffer
, y ponerlo enJSON::Value
. Pero cuando intento analizarlo, no encuentro el contenido del búfer en el objeto JSON.
El código es el siguiente.
Json::Value root;
Json::Reader reader;
Json::StyledWriter writer;
int length;
char * buffer;
ifstream is;
is.open ("D:\\test.j2k", ios::binary);
// get length of file:
is.seekg (0, ios::end);
length = is.tellg();
is.seekg (0, ios::beg);
// allocate memory:
buffer = new char [length];
// read data as a block:
is.read (buffer,length);
root["sample"] = *buffer;
writer.write(root);
cout << root;
const string rootAsString = root.toStyledString();
cout << rootAsString << endl;
Como soy nuevo en VC ++, no estoy seguro de que leer un archivo de imagen en char * buffer sea correcto o incorrecto. Por favor, hágamelo saber qué está mal con el código Gracias.