-4

I calling wsdl webservice and get following JSON string

eg :

$result = '
{
"Value":
[
{"Username":"CustomerName1","Password":"123","ResellerID":"888"},{"Username":"CustomerName2","Password":"123orAnyChar","ResellerID":"378"}
],
"Error":{"Check":false,"Msg":"No Error!"}
}
';

How to convert this php code to java code :

Example php code :

$MyArray = json_decode($result, true);
if (array_key_exists("Error", $MyArray)) {
 if ($MyArray['Error']['Check'] != true) {
 foreach ($MyArray['Value'] as $Key => $Val) {
 echo "Username = ".$Val['Username']." , Pass = ".$Val['Password']." , ResID = ".$Val['ResellerID']."\r\n";
 }
 }
 else {
 echo "Error Msg";
 }
}

Note : just convert this php code block to java, using sample json string

thanks

asked Jan 4, 2015 at 21:08
1

1 Answer 1

0

Answer for my question is :

try {
 // result is json string
 Boolean ErrStatus = true;
 JSONObject CheckErr = new JSONObject(result).getJSONObject("Error");
 ErrStatus = CheckErr.getBoolean("Check");
 String Msg = "";
 if (ErrStatus == false) {
 JSONArray jArray = new JSONObject(result).getJSONArray("Value");
 for (int i = 0; i < jArray.length(); i++) {
 JSONObject json = jArray.getJSONObject(i);
 Msg = Msg + "Username : " + json.getString("Username") + "\n" + "Password : " + json.getString("Password") + "\n\n";
 }
 Msg = "Info correct";
 }
 else {
 Msg = CheckErr.getString("Msg");
 }
 txtLogin.setText(s);
 }
 catch (Exception e) {
 Log.i("WS", "Error JSON");
 }
answered Jan 5, 2015 at 10:59
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.