At first glance your data looks like a JSON object but in reality it is not. Then, to extract the email you can resort to regular expressions, looking for anything between eMail=
and ,
:
I have edited the question with a complete program.
DEMO
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
class ExtraerEmail
{
public static void main (String[] args) throws java.lang.Exception
{
String text = "{Telefono =0,[email protected],monto=$54977,Numero Documento=0,Origen de Pago:=Subsidio,Tipo de Pago:=Transferencia,Banco=RABOBANK CHILE,Tipo de Cuenta=CUENTA VISTA,Numero de Cuenta=0003331111}";
final Pattern pattern = Pattern.compile("eMail=(.+?),"); //buscar valor entre eMail= y ,
final Matcher matcher = pattern.matcher(text);
matcher.find();
String sEmail=matcher.group(1); //Extraer cadena encontrada
System.out.println("Este es el email: "+ sEmail); // Prints String I want to extract
}
}
Result
This is the email: [email protected]
@Deprecated
It is not a JSON object, ignore what follows:
What you submit is Json object, called in Java JSONObject . OJo a JSON object is not the same as a JSONArray.
To read the email it would be something like this:
JSONObject obj = new JSONObject(str);
String email = obj.getString("eMail");
Note:
I assume that str
is the variable that you print to show you the values between {}
. If it's not a string, but a JSON itself, you get the email by calling .getString("eMail")
on the name of your Json object directly.
See the Java Help .