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 "";
}
}
}