Skip to content

create json instance from raw json (unsigned char*) #431

Closed

Description

@CheyenneForbes

I cant get nor set values if I try :

basic_ostream BOS = get_json_from_server(); // the json response from a server
json BOS_json = BOS;

If I am doing something wrong, whats the right way to create a json instance from raw json received from a webserver as basic_ostream?

Activity

  1. CheyenneForbes commented on Jan 20, 2017

    @CheyenneForbes
    Author

    Can anyone help me?

  2. gregmarr commented on Jan 20, 2017

    @gregmarr
    Contributor

    You need to have an istream, not an ostream.

  3. CheyenneForbes commented on Jan 20, 2017

    @CheyenneForbes
    Author

    What can I do if the http client I am using returns the response body as a "basic_ostream"?

  4. gregmarr commented on Jan 21, 2017

    @gregmarr
    Contributor

    That seems to be an odd thing for it to return. What client are you using?

  5. CheyenneForbes commented on Jan 21, 2017

    @CheyenneForbes
    Author

    it was made by a friend, I was reading wrong, it actually returns "unsigned char*" and not "basic_ostream", my apologies.

    but it doesnt work still, how can I create a nlohmann::json instance from json (not Serialized) returned from a server?

  6. changed the title [-]create json instance from basic_ostream[/-] [+]create json instance from raw json (unsigned char*)[/+] on Jan 21, 2017
  7. gregmarr commented on Jan 21, 2017

    @gregmarr
    Contributor

    json::parse()

  8. CheyenneForbes commented on Jan 21, 2017

    @CheyenneForbes
    Author

    that gives "Segmentation fault"

  9. gregmarr commented on Jan 21, 2017

    @gregmarr
    Contributor

    Where is the segmentation fault (stack trace)? It could be a problem with the string itself. Do you get the same fault if you use strlen() on the string?

  10. nlohmann commented on Jan 21, 2017

    @nlohmann
    Owner

    @CheyenneForbes As @gregmarr said, the parse function can handle char *. Can you please add more precise description of your errors?

  11. nlohmann commented on Jan 23, 2017

    @nlohmann
    Owner

    @CheyenneForbes Any update?

  12. CheyenneForbes commented on Jan 23, 2017

    @CheyenneForbes
    Author

    Hey, sorry for the delayed response, the client was actually sending a POST request instead of a GET request so the json instance was actually "empty bytes" when I was trying to add/get data, I thought the issue was with the json instance because when I opened the link in the browser it worked. I recommend that anyone using the json header file and plan to receive the json data from "outside" should do so in a try{}catch(){} block when application crashes due to "empty" data arent "acceptable", for example when being used in a web server

  13. nlohmann commented on Jan 23, 2017

    @nlohmann
    Owner

    Thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions