JSONでgetString()とoptString()

544 ワード

The difference is that  optString  returns the empty string ( "" ) if the key you specify doesn't exist. getString  on the other hand throws a  JSONException . Use  getString  if it's an error for the data to be missing, or  optString  if you're not sure if it will be there.
optStringとgetStringの違いは、必要なString特殊字が存在しない場合、optStringは「」を返します.getStringは異常を放出します.だから、もしあなたが確定していない場合は、できるだけoptStringを使用します.getStringを使用するには、dataが失われたことを確認する必要があります.