Skip to content

Instantly share code, notes, and snippets.

View nickyrabit's full-sized avatar
🏠

Nicholaus Legnard nickyrabit

🏠
View GitHub Profile
@nickyrabit
nickyrabit / nulljson.java
Last active April 15, 2019 10:59
How to handle null json key when processing JSON Object in Java and Android
//in my example im creating a json object from json array
JSONObject object = jArr.getJSONObject(i);
//getting an JSONArray from JSONObject
JSONArray roleJSONArray = object.getJSONArray("roles");
//This is where i check the null json object if "location" value comes null
//Step 1: check if its null using isNull
if(object.isNull("location")){
//override the key value from location to another value
object.put("location", "N/A");
@gkhays
gkhays / JSON-Remove.md
Last active July 18, 2018 12:03
Remove an attribute or element from a JSON array during enumeration

Remove a JSON Key While Iterating

I want to remove any JSON key/value pairs wherein the value is the empty string "" or is the string literal null. However Java enumerations don't like that and will throw a ConcurrentModificationException if you attempt to remove the key and value.

JSONArray ja = loadJSONArray();
JSONObject firstJSON = ja.getJSONObject(0);
Iterator<?> iter = firstJSON.keys();
for (int i = 0; i < ja.length(); i++) {
	JSONObject json = ja.getJSONObject(i);
@spearsmarketing
spearsmarketing / HTML code to make a phone number clickable
Last active October 23, 2018 12:26
Clickable Phone Number HTML Code
<a href="tel:555-555-5555">555-555-5555</a>