Skip to content

Global std::vector from json #2108

Closed
Closed
@Xillez

Description

Hello!

I've noticed that this is a recurring issue and have been looking thought closed and open issues for any solutions, but for some reason getting a vector containing a custom type from json throws "[json.exception.type_error.302] type must be array, but is null" which is based on exception.what()'s output.

I have this JSON file:

[
   {
      "date":"20200116",
      "id":1589,
      "path":"D:\\_projects\\ChickenIdentifier\\P3-1589_L_20200116.jpg",
      "penName":"P3",
      "side":76
   },
   {
      "date":"20200116",
      "id":1589,
      "path":"D:\\_projects\\ChickenIdentifier\\P3-1589_R_20200116.jpg",
      "penName":"P3",
      "side":82
   },
   {
      "date":"20200116",
      "id":1592,
      "path":"D:\\_projects\\ChickenIdentifier\\P3-1592_L_20200116.jpg",
      "penName":"P3",
      "side":76
   },
   {
      "date":"20200116",
      "id":1592,
      "path":"D:\\_projects\\ChickenIdentifier\\P3-1592_R_20200116.jpg",
      "penName":"P3",
      "side":82
   }
]

What I've tried:

  • auto vec = j.get<std::vector<PictureInfo>>(); <-- Produces the same error
  • j.at("varName").get_to<std::vector<PictureInfo>>(c.required); <-- Dont think I can use since list doesnt have a name/key.
  • auto pics = j.get>();  //<-- Produces the same error
    

std::vector pics = (std::vector) pics;

Im using Win10 and MS Visual Studio Community 2019

Lib version: "JSON for Modern C++ version 3.7.3"

Appreciate any help and please let me know if anything else is needed

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions