Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle a kind of json like this? #8

Open
rgambardella66 opened this issue Oct 27, 2021 · 2 comments
Open

How to handle a kind of json like this? #8

rgambardella66 opened this issue Oct 27, 2021 · 2 comments

Comments

@rgambardella66
Copy link

[
{
"field1": "Donald Duck",
"field2": "sample text",
"field3": 0.5675269775390624,
"h": 490,
"attrfield": [
{
"attr1": "first attribute",
"attr2": "secod attribute"
},
{
"attr1": "first attribute",
"attr2": "secod attribute"
}
]
},
{
"field1": "Mickey Mouse",
"field2": "sample text",
"field3": 0.9995269775390625,
"h": 300,
"attrfield": [
{
"attr1": "first attribute",
"attr2": "secod attribute"
},
{
"attr1": "first attribute",
"attr2": "secod attribute"
}
]
}
]

when i try to map it into a struct I reach allways the following error:
terminate called after throwing an instance of 'struct_mapping::StructMappingException'
what(): parser: unexpected character '[' at line 1

@bk192077
Copy link
Owner

Unfortunately, the object is expected first. Arrays as the first elements are not yet supported (there is not enough time to expand the library). You can wrap your array in a structure, then everything will work.

{
  "arr": [
    {
      "field1": "Donald Duck",
      "field2": "sample text",
      "field3": 0.5675269775390624,
      "h": 490,
      "attrfield": [
        {
          "attr1": "first attribute",
          "attr2": "secod attribute"
        },
        {
          "attr1": "first attribute",
          "attr2": "secod attribute"
        }
      ]
    },
    {
      "field1": "Mickey Mouse",
      "field2": "sample text",
      "field3": 0.9995269775390625,
      "h": 300,
      "attrfield": [
        {
          "attr1": "first attribute",
          "attr2": "secod attribute"
        },
        {
          "attr1": "first attribute",
          "attr2": "secod attribute"
        }
      ]
    }
  ]
}

@rgambardella66
Copy link
Author

That's true, I'll follow your suggest, thanks a lot for your answer: I've really appreciate this library.
Best Regards!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants