Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Dataset Json de-serialization problem.

$
0
0

I am currently having a problem trying to de-serialize a Json dataset in an iOS application I am developing (Xamarin Studio).

I am using the Json.NET component from the Xamarin component store to try attempt to do this. I am also using the same library in my WCF restful web service.

Here is the code I use in the web service to serialize the dataset:

DataSet dataSet = new DataSet("PersonDataSet");
dataSet.Tables.Add(sharedDataAccess.GetPersonData()); 
string jsonSerialized = JsonConvert.SerializeObject(obj);
return jsonSerialized

This works perfectly fine and returns the Json string below (only included 2 people for simplicity):

{
    "Person": [{
        "PersonId": 1,
        "LanguageId": 4,
        "Title": "Mr",
        "Name": "Alfred",
        "Initials": "A",
        "Surname": "Zulu",
        "RSAIDNumber": "6605315423087",
        "IsActive": true,
        "LastUpdatedDate": "2014-03-28T00:00:00",
        "LastUpdatedUserId": 560,
        "InsertedDate": "2014-03-28T00:00:00",
        "InsertedUserId": 560,
        "Qualification": null,
        "QualificationCode": null,
        "QualificationYearObtained": null,
        "FSBAppointmentDate": "2014-03-28T00:00:00",
        "MatriculatedYear": null,
        "MatriculatedRegion": null,
        "MatriculatedSchool": null,
        "DateAppointed": "2009-01-09T00:00:00",
        "DateExitedCompany": "1900-01-01T00:00:00"
    }, {
        "PersonId": 2,
        "LanguageId": 4,
        "Title": "Mr",
        "Name": "Monwabisi",
        "Initials": "M",
        "Surname": "Paul",
        "RSAIDNumber": "7511295275084",
        "IsActive": true,
        "LastUpdatedDate": "2014-03-19T00:00:00",
        "LastUpdatedUserId": 177,
        "InsertedDate": "2014-03-19T00:00:00",
        "InsertedUserId": 177,
        "Qualification": null,
        "QualificationCode": null,
        "QualificationYearObtained": null,
        "FSBAppointmentDate": "2014-03-19T00:00:00",
        "MatriculatedYear": null,
        "MatriculatedRegion": null,
        "MatriculatedSchool": null,
        "DateAppointed": "2010-11-22T00:00:00",
        "DateExitedCompany": "1900-01-01T00:00:00"
    }]
}

I tested the web service by writing a small console app and it worked perfectly. I could get the DataTable from the DataSet.

public void TestWebCall ()
{
WebRequest request = HttpWebRequest.Create("http://localhost/MobileDeviceRest.Service/MobileDeviceSharedService.svc/wh/Person");
            request.ContentType = "application/json";
            request.Method = "GET";
            request.Proxy = null;
            using (var response = (HttpWebResponse)request.GetResponse())
            {
                using(StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    var content = reader.ReadToEnd();
                    System.Data.DataSet ds = JsonConvert.DeserializeObject(content);
                    System.Data.DataTable dt = ds.Tables["Person"];
                }
            }
}

Doing the exact same method as above in Xamarin Studio for an iOS application does not work though. I am able to de-serialize the Dataset without error, but it is empty. Subsequently when I try getting the DataTable out of the DataSet, the DataTable is null.

I went further and checked if the simple code example that is on the Json.NET website that shows how to de-serialize a simple DataSet works in Xamarin Studio using the Json.NET component from the Xamarin component store. This was also able to convert the Json string into a DataSet, but it was empty as well.

Any help would be appreciated.

Thanks.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>