数据库数据保存为字符串

时间:2015-10-10 16:36:31

标签: java android json

是否可以从数据库中检索数据(TAG_NAME)并将其另存为字符串?

private static final String TAG_NAME = "name";

protected String doInBackground(String... args) {
    int success;
    try {

        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("phonenum", phonenum));

        JSONObject json = jsonParser.makeHttpRequest(
                url_product_details, "GET", params);

        Log.d("Single Product Details", json.toString());

        success = json.getInt(TAG_SUCCESS);
        if (success == 1) {

            JSONArray productObj = json
                    .getJSONArray(TAG_PRODUCT); // JSON Array

            JSONObject product = productObj.getJSONObject(0);

我只能将数据显示为textview,但我想将数据保存为字符串。

            // product with this pid found

            txtwelcome = (TextView) findViewById(R.id.txtname);

            // display product data in EditText
            txtwelcome.setText(product.getString(TAG_NAME));

我尝试使用它将其保存为字符串,但它不起作用。

            username = product.getString(TAG_NAME);

0 个答案:

没有答案
相关问题