Reading json files in C++

前端 未结 7 2083
梦如初夏
梦如初夏 2021-02-01 03:17

I\'m trying to read in a JSON file. So far I have focused on using the jsoncpp library. However, the documentation is quite hard to understand for me. Could anyone

7条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 04:03

    storing peoples like this

    {"Anna" : { 
      "age": 18,
      "profession": "student"},
    "Ben" : {
      "age" : "nineteen",
      "profession": "mechanic"}
     }
    

    will cause problems, particularly if differents peoples have same name..

    rather use array storing objects like this

    {
      "peoples":[
           { 
               "name":"Anna",  
               "age": 18,
               "profession": "student"
           },
           {
               "name":"Ben",
               "age" : "nineteen",
               "profession": "mechanic"
           } 
      ]
    }
    

    like this, you can enumerates objects, or acces objects by numerical index. remember that json is storage structure, not dynamically sorter or indexer. use data stored in json to build indexes as you need and acces data.

提交回复
热议问题