Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » Binary file to JSON
Binary file to JSON [message #40780] Mon, 16 September 2013 08:23 Go to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
I'm trying to store binary file as json and load from it:
FileIn fs(someFile);

String buf = fs.Get(size);

ValueArray json = ParseJSON(Json()("buf", buf).ToString());
ASSERT(json.GetCount() == 1);
String s = json[0];
ASSERT(s == buf);//=>break: s contain at end some like 'f', 'r', 'e', 'e'

[Updated on: Mon, 16 September 2013 08:23]

Report message to a moderator

Re: Binary file to JSON [message #40781 is a reply to message #40780] Mon, 16 September 2013 10:11 Go to previous messageGo to next message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
In other words, why
buf != ParseJSON(Json()("buf", buf).ToString())[0]

if buf is a string from binary file (with text file all Ok)

[Updated on: Mon, 16 September 2013 10:11]

Report message to a moderator

Re: Binary file to JSON [message #40782 is a reply to message #40781] Mon, 16 September 2013 10:33 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Json does not really support binary data. I recommend using Base64Encode/Decode for the task (that is what I do when I need binary data in Json).
Re: Binary file to JSON [message #40783 is a reply to message #40782] Mon, 16 September 2013 10:41 Go to previous message
iST1 is currently offline  iST1
Messages: 107
Registered: August 2013
Experienced Member
Perfectly, something I was looking for. Thanks!
Previous Topic: Time::Set(int64 scalar) unexpected results
Next Topic: Link problem on linux
Goto Forum:
  


Current Time: Thu Mar 28 18:44:39 CET 2024

Total time taken to generate the page: 0.01479 seconds