Question

I have a problem to convert an Array of Json to use it in Winforms. I am sending the Json array with a PHP web service , its works very well. I am using Nusoap and generated myclasses from MySQL DB with Structy.

This is my Nusoap Code:

<pre> 
<?php

    require_once "lib/nusoap.php";
    include_once '../Classes/_config.inc.php';
    include_once '../Classes/Database.class.php';
    include_once '../Classes/client.class.php';

//on initialise un nouvel objet serveur 

    $server = new soap_server(); 



     // on configure en donnant un nom et un Namespace 

    $server->configureWSDL("WebService Client","client");

    $server->register('getClient',array(),  array('return'=>'xsd:string'),'client');



    function getClient(){

    $client = client::readArray(array());

    $arrayForJs = []; 


    foreach($client as $item)
    { 
    array_push($arrayForJs,['Nom'=>$item->getNom(),'Prenom'=>$item->getPrenom()]);
    } 

        return json_encode($arrayForJs);





}

 $server->service($HTTP_RAW_POST_DATA);

 ?>

and my .net code:

 private void button1_Click(object sender, EventArgs e)
        {
            SimpleService.WebService.WebServiceClient soap = new SimpleService.WebService.WebServiceClient();
            string JsonEncoded;
            JsonEncoded = soap.getClient();
            MessageBox.Show(JsonEncoded);
     }

The array returns well-formed:

[{"Nom":"Ahmed","Prenom":"Maiza"},{"Nom":"Moez","Prenom":"Jbiss"},{"Nom":"Bugan","Prenom":"Suzy"},{"Nom":"Leoin","Prenom":"Patrick"}]

I want to decode this and use it to show its in Winforms.

I used Newtonsoft and System.Web.Script.Serialization but I couldn't get it to work.

So please, what can I do, and when I want to parse the data from C# to my DB, what can I use ?

Was it helpful?

Solution 2

Thanks that worked for me but i didnt Call the Jayrock

   List<Client> listeclient = JsonConvert.DeserializeObject<List<Client>>(JsonEncoded);

        foreach (Client nom in listeclient)
        {
            MessageBox.Show(nom.Nom);
            MessageBox.Show(nom.Prenom);
        }

OTHER TIPS

You can use a library called Jayrock for that, it is available @ http://jayrock.berlios.de/

List<User> UserList = JsonConvert.DeserializeObject<User>(jsonString);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top