Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8007125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:43:41+00:00 2026-06-04T17:43:41+00:00

I am trying to use JSON cpp with VS2008. Can anyone tell me is

  • 0

I am trying to use JSON cpp with VS2008.

Can anyone tell me is it possible to pack binary data into JSON format? I am reading a image file into char* buffer, and putting it in JSON::Value. But when i try to parse it, I don’t find the buffer contents in the JSON object.

Code is as follows.

    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;

Since I am new to VC++, I am not sure whether reading a image file to char * buffer is right/wrong. Please let me know whats wrong with the code. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:43:42+00:00Added an answer on June 4, 2026 at 5:43 pm

    You must encode it because JSON is a subset of javascript structures format as it appears in javascript source code.

    The most frequently used encoding for binary data in JSON is Base64. I use it (in other languages than c++) for encoding images without problems. You simply have to prefix the encoded image with data:image/png;base64, (supposing it’s png) to have it automatically decoded in javascript if you set this to the src of an image.

    EDIT : as in any other language, base64 encoding in C++ is easy. Here’s a library : https://github.com/ReneNyffenegger/development_misc/tree/master/base64

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use amcharts and I want to use JSON to format
I'm desperately trying to use json data to fill my dojo spider chart. First
I'm trying to use JSON.Net to deserialize a JSON object into a C# object.
I am trying to use use the following JSON data to create the following
I am trying to use JSON and HTTP client to retrieve data from a
Trying to learn how to use JSON and parse the json data.i am using
So I'm trying to use $.JSON to grab and access the data from this
I'm new to JSON and trying this tutorial: http://p-xr.com/android-tutorial-how-to-parse-read-json-data-into-a-android-listview/#comments I'm new to JSON, C
I am trying to output mysql query results into JSON format,but struggling to output
I'm trying to use Json with struts 2 and jquery, I am able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.