Android 扫描后来自二维码的Parson JSON对象
在我的二维码中,我有一个JSON对象:Android 扫描后来自二维码的Parson JSON对象,android,json,qr-code,Android,Json,Qr Code,在我的二维码中,我有一个JSON对象: JSONObject json = new JSONObject(); try { json.put("name", editTextName.getText().toString()); json.put("price", editTextPrice.getText().toString()); } catch (JSONException e) {
JSONObject json = new JSONObject();
try {
json.put("name", editTextName.getText().toString());
json.put("price", editTextPrice.getText().toString());
} catch (JSONException e) {
e.printStackTrace();
}
BarcodeQRCode barcodeQRCode = new BarcodeQRCode(json.toString(), 1000, 1000, null);
Image codeQrImage = barcodeQRCode.getImage();
codeQrImage.scaleAbsolute(100, 80);
document.add(codeQrImage);
但当我试图解析它时
//this is the qr code context after scanned, i just declared it for clarifications
String scannedQrCode = "\"name\":\"Nissan Urvan Original 12v\",\"price\":\"2500\"}";
try {
mainObject = new JSONObject(scannedQrCode);
String nameItem = (String) mainObject.get( "name" );
String priceItem = (String) mainObject.get( "price" );
Log.e("TESTING",""+nameItem +priceItem);
} catch (JSONException jsonException) {
jsonException.printStackTrace();
}
日志中说:
org.json.JSONException:类型为java.lang.String的值名称不能为空
转换为JSONObject
我的json对象有问题吗?是否正在创建中?在
“name\”:“Nissan Urvan Original 12v\”,“price\”:“2500\”}中添加起始{
:
"{\"name\":\"Nissan Urvan Original 12v\",\"price\":\"2500\"}"