我有一些代码向我展示了json文件中的文本,但我想查看文本中是否有特定的单词。
这是我的代码:
if (currentLocation.distanceTo(myModel.getNearest()) < 500) {
if (said != true) {
String seriousWarning = (myModel.getNearest().getProvider());
tts.speak(seriousWarning, TextToSpeech.QUEUE_ADD, null);
said = true;
}
myModel.getNearest())在这里:
public Location getNearest(){
nearest = cameras.get(0);
return nearest;
}
和JSON文件:
{
"lng":0.18077 ,
"lat": 43.00854 ,
"name":"Orange Store",
"tribe":"1",
"id":"1",
"verified":"1"
},
我试过这个但是没有用:
if (currentLocation.distanceTo(myModel.getNearest()) < 500) {
if (said != true) {
String seriousWarning = (myModel.getNearest().getProvider());
tts.speak(seriousWarning, TextToSpeech.QUEUE_ADD, null);
said = true;
if (seriousWarning.equals("Orange"))
sign.setText("JAckbot");
}
非常感谢任何帮助。
答案 0 :(得分:0)
只需将文本存储在任何String变量中,如:
String s1 = [your text];
if(s1.contains([specific word]))
{
do something if text contains specific word
}else
{
do something is text do not contain word
}