문제

I am sending data to server using HttpPost in android which is successfully received by server. Now the server response is as follows:

<html><body>
<input type="text" id="nameL" name="nameL" value="Sam" />
<input type="text" id="level" name="level" value="Introductory"  />
</body></html>

How can I get value of http response using the input name attribute (e.g. nameL & level) on an Android client? I am able to get the string response but it contains all tags <html>....</html> (as above) in one string.

도움이 되었습니까?

해결책

Use an HTML parser. I personally like jsoup:

Document doc = JSoup.parse(responseString);
String nameL = doc.select("input[name=nameL]").attr("value");
String level = doc.select("input[name=level]").attr("value");

However, as VenomVendor pointed out, it is unusual (and inefficient, by the way) to use HTML for API-like communication.

다른 팁

Either generate JSON or XML response from server side.
Use XML Parsing or JSON PARSING to retrieve data.

your current response will be useful, only when you are adding the response to WebView

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top