Reputation: 979
I am trying to create a simple Android app to get data from Web Services server. I have created a database with fake weather data and configured Web Service When I run this code from Android app:
SoapObject results = (SoapObject) envelope.bodyIn;
result = results.getProperty("getAlertsResult").toString();
the result string is below. How can I get single alert message, name and priority from the soap object? Thank you.
anyType{schema=anyType{element=anyType{complexType=anyType{choice=anyType{element=anyType{complexType=anyType{sequence=anyType{element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; }; }; }; }; }; }; }; diffgram=anyType{NewDataSet=anyType{Table=anyType{ALERT_ID=1; ALERT_TYPE=WEATHER; ALERT_NAME=SEVERE STORM IN THE AREA; ALERT_MSG=THIS IS AN EXTREMELY DANGEROUS SITUATION WITH TORNADO LIKE WIND SPEEDS EXPECTED.; ALERT_PRIORITY=HIGH; ALERT_ENABLED=1; ALERT_USER=Administrator; ALERT_DATETIME=2012-07-24T00:00:00-04:00; }; Table=anyType {ALERT_ID=2; ALERT_TYPE=WEATHER; ALERT_NAME=FLOOD WARNING; ALERT_MSG=THE NATIONAL WEATHER SERVICE IN MORRISTOWN, TN HAS ISSUED A FLOOD ; ALERT_PRIORITY=NORMAL; ALERT_ENABLED=1;ALERT_USER=Administrator; ALERT_DATETIME=2012-07-24T00:00:00-04:00; }; Table=anyType{ALERT_ID=3; ALERT_TYPE=EARTHQUAKE; ALERT_NAME=7.1 HEARTHQUAKE ON THE AREA; ALERT_MSG=A SEVERE EARTHQUAKE REGISTRED IN METRO AREA AT 2:30PM EST, WITH 7.1 RS; ALERT_PRIORITY=HIGH; ALERT_ENABLED=1; ALERT_USER=Administrator; ALERT_DATETIME=2012-07-24T00:00:00-04:00; }; }; }; }
Upvotes: 0
Views: 2799
Reputation: 979
Here is the code to get single SoapObject property.
SoapObject resultOne = (SoapObject) results.getProperty(0);
SoapObject resultTwo = (SoapObject) resultOne.getProperty(1);
SoapObject allAlerts = (SoapObject) resultTwo.getProperty(0);
SoapObject alertOne = (SoapObject) allAlerts.getProperty(0);
SoapPrimitive alertPriority = (SoapPrimitive) alertOne.getProperty(4);
Upvotes: 2
Reputation: 2528
What you could do is making a php query wich retrieves the data and put it in json format. json is a very good format for sharing cross platform data. like this
<?php
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$result = mysql_query("SELECT * FROM table_name") or die(mysql_error());
if (mysql_num_rows($result) > 0) {
$response["forecasts"] = array();
while ($row = mysql_fetch_array($result)) {
//here you put all the rows from the column that you have retrieved
$product = array();
$product["column1"] = $row["column1"];
$product["column2"] = $row["column2"];
array_push($response["forecasts"], $product);
}
$response["success"] = 1;
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "No games found";
echo json_encode($response);
}
?>
the process the json data u can use the gson library wich is verry good in parsing json to objects
Upvotes: 0