source: java/ModDepotAccess/src/net/oni2/moddepot/JSONHelpers.java@ 1089

Last change on this file since 1089 was 748, checked in by alloc, 12 years ago

java lib: Mod depot access

File size: 663 bytes
Line 
1package net.oni2.moddepot;
2
3import org.json.JSONException;
4import org.json.JSONObject;
5
6/**
7 * @author Christian Illy
8 */
9public class JSONHelpers {
10 /**
11 * Return the string associated with the given key or null if the key does
12 * not exist or does not contain a string
13 *
14 * @param parent
15 * Parent JSON object
16 * @param key
17 * Key to look for
18 * @return Contained string or null
19 */
20 public static String getStringOrNull(JSONObject parent, String key) {
21 try {
22 Object obj = parent.get(key);
23 if (obj instanceof String)
24 return (String) obj;
25 } catch (JSONException e) {
26 e.printStackTrace();
27 }
28 return null;
29 }
30}
Note: See TracBrowser for help on using the repository browser.