1

I am writing a program which needs to parse a json I don't know the exact format. The important data can be stored in multiple possible keys. For simplicity's sake let's say the names of the keys can be either "A" or "B". I don't know which it will be and I also don't know if the value will be a string, an integer or even an array. I just want to save the value of "A" or "B" as a string for later use. Is there a way to do that in cJSON especially in case for the array?

notAuser
  • 31
  • 3
  • 1
    I'm not a regular user of cJSON but can guess like most json APIs it should have a way to iterate over each an object. Looks like `cJSON_ArrayForEach` is available. Use that to get each object field. Then get the key name via the `string` field and the type can be obtained via the `cJSON_Is` functions. – kaylum Sep 06 '21 at 20:39
  • 1
    Welcome to StackOverflow! Please take the [tour] to learn how this site works. You might want to [edit] your question, providing some examples of possible JSON, and what you considered so far. – the busybee Sep 07 '21 at 08:37
  • 2
    Sorry for this maybe suboptimal type of question. @kaylum your answer actually helped. I'm new to that api and parsing json in general so this little hint was exactly what I needed :) – notAuser Sep 08 '21 at 15:42
  • Please provide enough code so others can better understand or reproduce the problem. – Community Sep 11 '21 at 15:39

0 Answers0