A for android
A for android

Reputation: 168

deserialize dataset in xamarin forms

How can you decrypt/ deserialize dataset. here is what i am getting from the web service. I am new to xamarin forms. Thanks in advance. i tried this json2csharp.com to convert, but got an error because it can convert datatable to csharp but not datasets.

    [  
   [  
      {  
         "bit_HasError":false,
         "vchar_ErrorMsg":""
      }
   ],
   [  
      {  
         "int_SurveyQuestionID":1,
         "vchar_Description":"we",
         "vchar_Instruction":"Question Instruction",
         "int_AnswerType":1
      },
      {  
         "int_SurveyQuestionID":5,
         "vchar_Description":"this is the question 2",
         "vchar_Instruction":null,
         "int_AnswerType":2
      }
   ],
   [  
      {  
         "int_SurveyQuestionID":1,
         "vchar_Option":"option1"
      },
      {  
         "int_SurveyQuestionID":5,
         "vchar_Option":"answer1"
      },
      {  
         "int_SurveyQuestionID":5,
         "vchar_Option":"answer2"
      },
      {  
         "int_SurveyQuestionID":5,
         "vchar_Option":"answer3"
      },
      {  
         "int_SurveyQuestionID":1,
         "vchar_Option":"optionn2"
      }
   ]
]

Upvotes: 0

Views: 330

Answers (1)

EvZ
EvZ

Reputation: 12179

Using https://app.quicktype.io/ it is quite easy to get started, just copy paste your json in there, here is the result:

// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
//    using QuickType;
//
//    var prject = Prject.FromJson(jsonString);

namespace QuickType
{
    using System;
    using System.Collections.Generic;

    using System.Globalization;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;

    public partial class Prject
    {
        [JsonProperty("bit_HasError", NullValueHandling = NullValueHandling.Ignore)]
        public bool? BitHasError { get; set; }

        [JsonProperty("vchar_ErrorMsg", NullValueHandling = NullValueHandling.Ignore)]
        public string VcharErrorMsg { get; set; }

        [JsonProperty("int_SurveyQuestionID", NullValueHandling = NullValueHandling.Ignore)]
        public long? IntSurveyQuestionId { get; set; }

        [JsonProperty("vchar_Description", NullValueHandling = NullValueHandling.Ignore)]
        public string VcharDescription { get; set; }

        [JsonProperty("vchar_Instruction")]
        public string VcharInstruction { get; set; }

        [JsonProperty("int_AnswerType", NullValueHandling = NullValueHandling.Ignore)]
        public long? IntAnswerType { get; set; }

        [JsonProperty("vchar_Option", NullValueHandling = NullValueHandling.Ignore)]
        public string VcharOption { get; set; }
    }

    public partial class Prject
    {
        public static List<List<Prject>> FromJson(string json) => JsonConvert.DeserializeObject<List<List<Prject>>>(json, QuickType.Converter.Settings);
    }

    public static class Serialize
    {
        public static string ToJson(this List<List<Prject>> self) => JsonConvert.SerializeObject(self, QuickType.Converter.Settings);
    }

    internal static class Converter
    {
        public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
        {
            MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
            DateParseHandling = DateParseHandling.None,
            Converters = {
                new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
            },
        };
    }
}

P.S.: Please note that you have to modify the class names.

Upvotes: 1

Related Questions