Samy Massoud
Samy Massoud

Reputation: 4385

PHP webservice return mixed data how can i use it in c#

i have web service in php which contain method (login) that should return false or associated array !

iam trying to use it in c# , but c# keep telling me that i must use object to handle returned data and so i did , but i cant parse anything of data

this is a glimpse of code

        object user;
        user = Chat.login(txtUsername.Text,txtPassword.Text);

        if (user.Equals(false))
        {
            MessageBox.Show("Error !");
        }
        else {
           //i wanna here for example show user['name'] for example
        }

the above code works fine if user entered wrong data , and if it's in system it return mixed data (array of user data) but i can't use it

Upvotes: 1

Views: 267

Answers (1)

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57660

You should rewrite the webservice so that it returns an object instead of two different types. In JSON it should look like,

{"status": "SUCCEDED", "result": [1,2,3,4]} // valid login
{"status": "FAILED"} // valid login

Then you can check if status is "SUCCEDED".

Another approach is to return an array. On success return associative array. On failure return an empty array. This allows you to check the length of the array to determine the success.

[1,2,3,4] // valid login
[] // valid login

The example is in JSON. You can convert it to XML anyway. Most important thing is that you should have got the idea.

Upvotes: 1

Related Questions