简体   繁体   中英

What's the difference between clear and arrayValue in jsoncpp

To work with json using a library jsoncpp. Previously created an array of objects can be cleared by clear .

Json::Value value;
...
value.clear();

Also, it can be purified by arrayValue (or nullValue ).

Json::Value value;
...
value = Json::arrayValue;

Question: What's the difference between clear and arrayValue ?

Clear= Remove all object members and array elements.

nullvalue = Means a empty value.

null, empty array, and empty object are three different things in JsonCpp.

value.clear() does the following:

  • null -> null
  • any array -> empty array
  • any object -> empty object
  • anything else -> throw std::runtime_error

value = Json:arrayValue does the following:

  • anything -> empty array

So the two constructs are not semantically equivalent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM