Comments (4)
Yeah, these all sound like they have a real chance to break existing code that relies on the existing behavior. Given it's an array of strings, if a change were to be implemented I think iterating through each element to check for NULL is the safest rather than assuming no further items will be valid. But the question of whether to add an empty string or skip the item entirely is probably fraught with edge cases.
I'm absolutely okay with working around the current behavior, because it gives me the most control over behavior. I just wasn't totally sure if there was already a helper somewhere, or if I was missing something more obvious. Thanks for the reply!
from cjson.
I agree. I think cJSON was intended to be a fairly simple or vanilla interface. I've seen a lot of other more special requests go by with different needs for this or that application, but for me, if I need a particular functionality, I just write my own small wrapper function and use that everywhere I need it.
from cjson.
As another work-around, you could find the actual number of strings in your allowed_values
array and pass that as the count parameter instead of the full size of the array. Perhaps a little more convenient than calling cJSON_AddItemToObject
for each actual string.
That said, I do think it would be most convenient if cJSON_CreateStringArray
were smarter. The question would be: what behavior would be most expected?
If all of the pointers after a certain point in the array are NULL, then an obvious approach would be for cJSON_CreateStringArray
to quit adding strings when it sees the first null pointer in the array, or if it has reached the count, whichever comes first.
But what if you pass an array of strings where there are spurious NULL pointers sprinkled throughout the array? Would the expected behavior be then to pluck out the non-null pointers and add those strings in, direct order, to the cJSON array object?
Or perhaps it should put blank (empty) strings in the locations where NULL values occur?
from cjson.
Thanks for the input and advice. I'll close this so it doesn't attract any further attention.
from cjson.
Related Issues (20)
- question on vxworks 6.8 HOT 3
- cJSON_DeleteItemFromArray considers dicts and arrays equally HOT 1
- Cannot Parse JSON HOT 5
- Add a function cJSON_IsEmpty() HOT 4
- JSON Parse Error HOT 11
- Always provide valuestring
- Double Free Vulnerability Discovered in cJSON_Delete Function Through Fuzzing HOT 6
- Fix cmake export to allow cross-compilation with sysroot HOT 1
- Regression on double precision in print_number() when fix a clang compile warning
- A segmentation fault in cJSON_SetValuestring HOT 2
- Can't Install it on PI HOT 2
- Weird Commits HOT 3
- Question: JSON Minifier
- print_number() non guaranteed to be thread safe with floating point numbers
- sorry,delete it
- misc_tests fails on 1.7.18 under Windows HOT 3
- Memory Leak in the cJSON_Free HOT 2
- Bug in print_string_ptr() increment is 4 instead of 5 HOT 2
- Unable to Specify macOS min version
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cjson.