I got an error message:
org.json.JSONException: Unterminated object at character 14 of {address: yo test}
I think I should avoid the string, but in vain by trying the whole method in StackOverflow.
Here is my code, thanks for the help:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try{
String str = getString(R.string.data);
JSONObject jsonObj = new JSONObject(str);
}
catch(Exception e){
Log.d("iLoveDrinkActivity", e.toString());
}
}
AND...
// res/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="data">{"address": "yo test"}</string>
</resources>
If the “address” is something like “test” or “yo” or “123”, everything works fine. Thanks again!!
source
share