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.
這個是在stackoverflow上面看到的,mark一下,簡單來說就是optString會在得不到你想要的值時候返回空字符串”“,而getString會拋出異常。