I am trying to read data from a complex json response(stored as a local file on my computer. Please check this link :
http://globalquran.com/download/data/download.php?data_by=json&quran_by_id[]=en.pickthall[
^](Its a 1 mb download only)
Actually this is a religious book stored in JSON format on my HDD.I directly generated Classes for It using JSON2Csharp where every verse is stored as a seperate property in the class EnPickthall . And every verse has it's own id, Surah(chapter),Aya(Verse Number) & Verse(Content of Verse).So I didn't use those classes and decided to create a custom class design for receiving JSON.
So I brought it down to this :
<pre lang="c#">using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using Windows.Storage;
using System;
namespace App_Code
{
public class QuranProxy
{
async public static void readQuran()
{
var serializer = new DataContractJsonSerializer(typeof(Verse));
var result = App_Code.FileIOHelper.ReadFromDefaultFile("ms-appx:///Assets/en.pickthall.json");
var ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
var data = (Verse)serializer.ReadObject(ms);
}
}
[DataContract]
public class Verse
{
[DataMember(Name = "id", IsRequired = true)]
public int id { get; set; }
[DataMember(Name = "surah", IsRequired = true)]
public int surah { get; set; }
[DataMember(Name = "ayah", IsRequired = true)]
public int ayah { get; set; }
[DataMember(Name = "verse", IsRequired = true)]
public string verse { get; set; }
}
}
I Get this message.Error : The data contract type 'App_Code.Verse' cannot be deserialized because the required data members 'ayah, id, surah, verse' were not found. I am using the file from "globalquran.com/download/data"
What I have tried:
Worked for around 2 days on finding a solution.