Java如何在不带引号的情况下写入数据库

时间:2019-07-07 11:14:37

标签: android firebase-realtime-database

我正在尝试写入Firebase数据库,而值中没有引号。下面是我写数据库时的代码。我需要添加什么来删除引号。

该图显示了我当前在数据库中得到的内容:

the image shows what I am currently getting in my database

public void onClick(View v) {
            TravelDetails travelDetails = new TravelDetails();
            GetDataFromText();
            travelDetails.setDropoffspot(kutadropoff);
            String numberpas=number_of_passengers;
            passengerholder=numberpas;
            String points=t_price;
            Kutapointholde=points;
            travelDetails.setPickupspot(kutapickup);
            travelDetails.setPassengernum(passengerholder);
            travelDetails.setPickuptime(kutatime);
            travelDetails.setKUtaPoints(Kutapointholde);
            FirebaseUser user = mAuth.getCurrentUser();
            String userID = user.getUid();
            myRef.child(userID).push().setValue(travelDetails);
            Button order_cab=(Button)v;
            order_cab.setVisibility(View.GONE);
            Toast.makeText(getApplicationContext(), " KUTA Ordered. Please wait not less than 15minutes for your taxi to arrive", Toast.LENGTH_SHORT).show();

        }
    });

}

public void GetDataFromText() {

    kutadropoff = from_edit_txt.getText().toString();
    kutapickup = to_edit_txt.getText().toString().trim();
    kutatime=time.getText().toString().trim();


}[enter image description here][1]

我希望数据库中的值(尤其是数字)上没有qoutation标记

2 个答案:

答案 0 :(得分:1)

那些引号只是告诉您您已向数据库中写入了一个字符串,而不是一个没有引号的数字。它们不是文字字符串值的一部分。如果您读回数据,它将没有引号。

答案 1 :(得分:0)

似乎您的TravelDetails类将kutaPoints定义为String,然后Firebase才将其写入数据库。如果要写数字,请确保TravelDetails.kutaPoints是数字:

public class TravelDetails {
  private double kutaPoints;

  ...

  public double getKutaPoints() { return this.kutaPoints; }
  public void setKutaPoints(double point) { this.kutaPoints = points; }
  ...
}

然后使用以下命令设置其值:

travelDetails.setKutaPoints(Double.valueOf(Kutapointholde));