2014-12-06 2 views
0

Отправка URL POST и получение ответа по всему BufferredReader, ответ приходит в ASCII. Как входящая строка может разбиваться на куски и использовать только нужную строку?Выбор ASCII в Java

params.put("ssl_result_format", "ASCII"); 

    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); 
    String line; 
    Receipt pp = new Receipt(); 
    pp.setVisible(true); 
    while ((line = in.readLine()) != null) {  
    Receipt.receText.append(line + "\n"); 
    System.out.println(line); 

Это как есть дисплей:

ssl_card_number=50**********3003 
ssl_exp_date=1215 
ssl_amount=12.00 
ssl_invoice_number= 
ssl_departure_date= 
ssl_completion_date= 
ssl_issue_points= 
ssl_promo_code= 
ssl_enrollment= 
ssl_result=0 
ssl_result_message=APPROVAL 
ssl_txn_id=051214A15-6E33E984-7C6B-466D-B38C-83F24BDAC631 ETC...... 

EDIT: Я ЗАВЕРШЕНА С ЭТИМ:

Properties prop = new Properties();   
    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); 
    prop.load(in); 
    String amount = prop.getProperty("ssl_amount"); 
    String card = prop.getProperty("ssl_card_number"); 
    String approval = prop.getProperty("ssl_approval_code"); 
    String results = prop.getProperty("ssl_result_message"); 
    String time = prop.getProperty("ssl_txn_time"); 
    String errorCode = prop.getProperty("errorCode"); 
    String errorMessage = prop.getProperty("errorMessage"); 
    String errorName = prop.getProperty("errorName");   
    if(errorCode == null){ 
    Receipt pp = new Receipt(); 
    pp.setVisible(true); 
    Receipt.amountLabel.setText(amount); 
    Receipt.cardLabel.setText(card); 
    Receipt.approvalLabel.setText(approval); 
    Receipt.respondLabel.setText(results); 
    Receipt.dateLabel.setText(time); 
    }else{ 
     JOptionPane.showMessageDialog(null,errorName,errorMessage,JOptionPane.ERROR_MESSAGE); 
      } 

+1 к Crunchify.com

+1

Этот вопрос не имеет смысла для меня. –

+0

Мне нужно только напечатать ssl_amount = 12, а не ответьте отверстие. – passw

+0

Используйте файл свойств. См.: Http://crunchify.com/java-properties-file-how-to-read-config-properties-values-in-java/ –

ответ

0

В вашем время цикла, проверка чтобы узнать, начинается ли линия с того, что вам нужно. Например,

while ((line = in.readLine() != null) { 
    if (line.startsWith("ssl_amount") { 
    Receipt.receText.append(line + "\n"); 
    System.out.println(line); 
    } 
} 
0

Используйте StringTokenizer разорвать строку и проверить первую часть строки, когда вы получите то, что вы хотите распечатать значение

params.put("ssl_result_format", "ASCII"); 

BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); 
String line; 
Receipt pp = new Receipt(); 
pp.setVisible(true); 
while ((line = in.readLine()) != null) {  
Receipt.receText.append(line + "\n"); 
StringTokenizer strToken = new StringTokenizer(line, "="); 
if(strToken.hasMoreTokens() && strToken.nextToken().equals("ssl_amount")) 
    System.out.println(strToken.nextToken());