将 android 字符串发送到 JSON 并在新的 window 中显示结果
Send android string to JSON and display result in new window
我正在使用 DVLA database,JSON 结果是,例如:
{
"make": "VOLKSWAGEN",
"model": "Tiguan",
"sixMonthRate": "112.75",
"twelveMonthRate": "205.00",
"dateOfFirstRegistration": "23 July 2009",
"yearOfManufacture": "2009",
"cylinderCapacity": "1968cc",
"co2Emissions": "167 g/km",
"fuelType": "DIESEL",
"taxStatus": "Not taxed",
"colour": "SILVER",
"typeApproval": "M1",
"wheelPlan": "2 AXLE RIGID BODY",
"revenueWeight": "Not available",
"taxDetails": "Tax due: 06 February 2015",
"motDetails": "Expires: 23 July 2015",
"taxed": false,
"mot": true
}
我的问题是,通过使用来自 editText 字段的 android 值
String str = results.getResults().get(0).getPlate();
EditText editText = (EditText)findViewById(R.id.edit_text);
editText.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
editText.setText(str, TextView.BufferType.EDITABLE);
如何将值 "str" 发送为:https://dvlasearch.appspot.com/DvlaSearch?licencePlate=**str**&apikey=DvlaSearchDemoAccount
以及如何在 JSON 或新的 window/tab 文本视图中显示结果?
我尝试使用这个包,但是 "putString" 突出显示为红色并且不知道如何将值发送给另一个 activity。
Intent intent = new Intent(MainActivity.this, DVLAresult.class);
捆绑捆绑=新捆绑();
intent.putString("PlateNumber", editText);
intent.putExtras(捆绑);
开始活动(意图);
这是我的第二个activity
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class DVLAresult extends AppCompatActivity {
Bundle bundle = getIntent().getExtras();
String finalPlateNumber = bundle.getString("PlateNumber");
}
问题是您试图将字符串放入 intent 而不是 bundle。
试试这个:
Intent intent = new Intent(MainActivity.this, DVLAresult.class);
Bundle bundle = new Bundle();
bundle.putString("PlateNumber", editText); //this line was the problem
intent.putExtras(bundle);
startActivity(intent);
我正在使用 DVLA database,JSON 结果是,例如:
{
"make": "VOLKSWAGEN",
"model": "Tiguan",
"sixMonthRate": "112.75",
"twelveMonthRate": "205.00",
"dateOfFirstRegistration": "23 July 2009",
"yearOfManufacture": "2009",
"cylinderCapacity": "1968cc",
"co2Emissions": "167 g/km",
"fuelType": "DIESEL",
"taxStatus": "Not taxed",
"colour": "SILVER",
"typeApproval": "M1",
"wheelPlan": "2 AXLE RIGID BODY",
"revenueWeight": "Not available",
"taxDetails": "Tax due: 06 February 2015",
"motDetails": "Expires: 23 July 2015",
"taxed": false,
"mot": true
}
我的问题是,通过使用来自 editText 字段的 android 值
String str = results.getResults().get(0).getPlate();
EditText editText = (EditText)findViewById(R.id.edit_text);
editText.setFilters(new InputFilter[] {new InputFilter.AllCaps()});
editText.setText(str, TextView.BufferType.EDITABLE);
如何将值 "str" 发送为:https://dvlasearch.appspot.com/DvlaSearch?licencePlate=**str**&apikey=DvlaSearchDemoAccount
以及如何在 JSON 或新的 window/tab 文本视图中显示结果?
我尝试使用这个包,但是 "putString" 突出显示为红色并且不知道如何将值发送给另一个 activity。 Intent intent = new Intent(MainActivity.this, DVLAresult.class); 捆绑捆绑=新捆绑(); intent.putString("PlateNumber", editText); intent.putExtras(捆绑); 开始活动(意图);
这是我的第二个activity
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class DVLAresult extends AppCompatActivity {
Bundle bundle = getIntent().getExtras();
String finalPlateNumber = bundle.getString("PlateNumber");
}
问题是您试图将字符串放入 intent 而不是 bundle。
试试这个:
Intent intent = new Intent(MainActivity.this, DVLAresult.class);
Bundle bundle = new Bundle();
bundle.putString("PlateNumber", editText); //this line was the problem
intent.putExtras(bundle);
startActivity(intent);