私はorg.json.JSONObjectを使用しています。これは、JSONObjectがnullかどうかをテストするために使用できる例です。
パッケージgeneral; Googleのgsonを使用して
JSONObject jsonObj = new JSONObject(jsonString);
System.out.println(jsonObj .isNull("error") ? " error is null ":" error is not null");
場合:あなたはcodehouseのJSONライブラリを使用している場合は
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
public class CheckNullInJSONObject {
public static void main(String[] args) {
JSONObject json = new JSONObject("{results : [{response:null}, {type:ABC}], error:null}");
JSONArray array = json.getJSONArray("results");
try {
for(int i = 0 ; i < array.length() ; i++){
JSONObject response = array.getJSONObject(i);
if (response.isNull("response")){
throw new Exception("Null value found");
}
}
}catch (Exception e) {
e.printStackTrace();
}
}
}
は、あなたが適用しようとするかもしれません正規表現。http://www.rexegg.com/regex-quickstart.html – kosa