Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
Nathan Minier 3-Apr-16 9:40am    
Can you post the App_Code.FileIOHelper.ReadFromDefaultFile method? That's likely to be your culprit.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900