Bunny83 / SimpleJSON

A simple JSON parser in C#
MIT License
735 stars 294 forks source link

get keys of JSONObject? #11

Closed amidofu closed 6 years ago

amidofu commented 6 years ago

Is it possible to add a method that returns the keys of JSONObject? I'm sure that Dictionary has this property. And is it possible to add AsLong for JSONNode?

Thank you

amidofu commented 6 years ago

oh sorry, it seems that the new version has the getter for Keys. but could you add AsLong for JSONNode? Thanks

Bunny83 commented 6 years ago

Well, of course it's possible to add an AsLong. However keep in mind that a JSONNumber is always represented as a double value. All Int32 values can be uniquely represented with a double. However not all long / Int64 values can be represented with a double. However it might be useful for converting a string to long.

About the keys you may also notice that JSONNode now has a struct enumerable to iterate over all key-value pairs. The enumerable always uses KeyValuePair as element. Though since this is also used for JSONArrays there is an implicit conversion from KeyValuePair<string, JSONNode> to JSONNode

amidofu commented 6 years ago

Thanks a lot!

Bunny83 commented 6 years ago

Just updated SimpleJSON.cs and included AsLong, I also added the setting JSONNode.longAsString to make the lazycreator use a JSONString instead of JSONNumber when using AsLong. If you need long values over the whole range of long you may want to set this to true.