XML空节点:<string /> 会被php的json_encode转换为string:{}
XML带文本节点的标签:<string>something</string> 会被php的json_encode转换为string:"something"
所以在读取时需要在java中判断
public static String getJSONString(JSONObject obj, String keyName) {
try {
obj.getJSONObject(keyName);
// If succeeded, it is KEYNAME:{} and should actually be an empty string
return "";
} catch (JSONException e) {
// If failed, it is a nonempty string (KEYNAME:"XXX")
try {
String keyString = obj.getString(keyName);
return keyString;
} catch (JSONException e1) {
// If failed again, it is of other data types.
return "";
}
}
}