Best way to populate data from online json

Hello,
Instead of using an Embedded resource json il like to download it online then populate Listview.
I'm not sure it's the best way but i use webclient called in App.xaml.cs.
But when app start it give me error System.IO.IOException: 'Sharing violation on path /data/user/0/com.Syncfusion.downjson/files/.local/share/insta.json'
Probably cause it was use by another stream...
Only way i found is to use DownloadStringTaskAsync and write it.
Is it populate too fast? Cause if i remove the binding for populate i can open it after app loaded.
Thanks for help.

PS: you need to add a "buy me a coffee" button for support :p or maybe in github


Attachment: downjson_18fa9363.zip

9 Replies 1 reply marked as answer

SS SaiGanesh Sakthivel Syncfusion Team August 25, 2020 12:16 PM UTC

Hi Milka,  
  
Thank you for contacting syncfusion support.  
  
We have checked the reported query “Best way to populate data from online json” from our end. We need more details about the query to analyze the sample.  
 
Could you please let us know your requirement in detail?  
Do you want to fetch the data from the online jSON data and then populate the collection in the view?  
 
Please share the above details which will be help us to check on it and provide you the solution as soon as possible.  
  
Regards,  
SaiGanesh Sakthivel 


MI milka August 25, 2020 02:55 PM UTC

Yes i like to fetch the data from the online jSON data and then populate the collection in the view then i think it s better download it  cause working also offline with cache.


SS SaiGanesh Sakthivel Syncfusion Team August 27, 2020 03:41 AM UTC

Hi Milka, 
 
Thank you for the update. 
 
We have checked the reported query “Best way to populate data from online json” from our end. We are currently working on it and update you further details on August 28, 2020. We appreciate your patience until then. 
 
Regards, 
SaiGanesh Sakthivel 



SS SaiGanesh Sakthivel Syncfusion Team August 31, 2020 03:52 AM UTC

Hi Milka, 
 
Thank you for the patience. 
 
We have checked the reported query “Best way to populate data from online json” from our end. We regret to inform you that we are facing same issue ‘System.IO.Exception: sharing violation on path’. We need more time to analysis the reported scenario and  update you further details on September 1, 2020. We appreciate your patience until then. 
 
Regards, 
SaiGanesh Sakthivel 



MI milka August 31, 2020 12:59 PM UTC

Hello,
I think it can be good to using a busyindicator on start ;)

Attachment: sample_5e607c9.zip


SS SaiGanesh Sakthivel Syncfusion Team September 1, 2020 12:28 PM UTC

Hi Milka,  
  
Thank you for the patience.  
  
We have checked the reported query Best way to populate data from online json from our end. we would like to inform you that json online link http://www.miaouapp.com/serena/insta.json which is provide by your side is not working. We request to provide the workable online Json link which will helps us to provide the solution as soon as possible.   
  
Regards,  
SaiGanesh Sakthivel  



MI milka September 1, 2020 01:38 PM UTC

sorry i have change it with a big file size for test. corrected now


LN Lakshmi Natarajan Syncfusion Team September 3, 2020 04:11 AM UTC

Hi Milka, 
 
Sorry for the inconvenience caused. 
 
We have checked the reported scenario in the sample provided. We would like to inform you that the sample works as expected from our side and the json data has been downloaded and stored in local. Also, we have tried to convert the json data to the collection, unfortunately, we are facing the following crash, 
 
Unhandled Exception: 
Newtonsoft.Json.JsonSerializationException: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[downjson.Models.Navigation.Album]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'albumInfos', line 2, position 15. occurred
 
We are currently checking to resolve the same crash and let you know the details on September 4, 2020. We appreciate your patience until then. 
 
Regards, 
Lakshmi Natarajan 



LN Lakshmi Natarajan Syncfusion Team September 5, 2020 03:31 AM UTC

Hi Milka, 
 
Thank you for your patience.  
 
We have checked the reported scenario from our side. We would like to inform you that you can retrieve data from json file using DeserializeObject method.  
 
You can install the Newtonsoft.Json package to the application to deserialize the json data. Please refer the following documentation regarding the same, 
 
Since, you are using json array data, you need to create class that replicates the json array structure like below, 
 
C#: Create RootObject class and create properties with the same json array names like AlbumInfos and Photos. 
public class RootObject 
{ 
    public Album[] AlbumInfos { get; set; } 
    public Photo[] Photos { get; set; } 
} 
 
C#: Retrieve json data using DeserializeObject and assign to RootObject instance. You can get the data for Album and Photos from the jsonData and set to ListView’s ItemsSource collection. 
async void OnButtonClicked(object sender, EventArgs args) 
{ 
    var localFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); 
 
    var fileText = File.ReadAllText(Path.Combine(localFolder, "milka.json")); 
 
    var jsonData = JsonConvert.DeserializeObject<RootObject>(fileText); 
    ViewModel.AlbumInfo = jsonData.AlbumInfos; 
 
    //You can retrieve data using StreamReader. 
    //using (StreamReader sr = new StreamReader(Path.Combine(localFolder, "milka.json"))) 
    //{ 
    //    var jsonText = sr.ReadToEnd(); 
    //    var jsonData = JsonConvert.DeserializeObject<RootObject>(jsonText); 
    //    ViewModel.AlbumInfo = jsonData.AlbumInfos; 
    //} 
} 
 
 
We have attached the modified sample in the following link, 
 
You can also refer to our online documentation to retrieve json data as dynamic, 
 
Please let us know if you need further assistance. 
 
Lakshmi Natarajan 
 


Marked as answer
Loader.
Up arrow icon