I am trying here to consume the data from a JSON file:
DATA.json
[
{"Label"
:"USA",
"Adress":"This is the us",
"Lat":"36.9628066",
"Lng":"-122.0194722"
},
{ "Label" :"USA",
"Address":"2020",
"Lat":"36.9628066",
"Lng":"-122.0194722" }
]
Then applying it in my Mainclass
:
using System.Collections.Generic;
using Xamarin.Forms.Maps;
using Xamarin.Forms;
using System.IO;
using Newtonsoft.Json;
using System;
namespace Orbage
{
class MapPage : ContentPage
{
public MapPage()
{
CustomMap customMap = new CustomMap
{
MapType = MapType.Street
};
// ...
Content = customMap;
var json = File.ReadAllText("File.json");
var places = JsonConvert.DeserializeObject<List<File>>(json);
foreach (var place in places)
{
CustomPin pin = new CustomPin
{
Type = PinType.Place,
Position = new Position(Double.Parse(place.Lat), Double.Parse(place.Lng)),
Label = place.Label,
Address = place.Address,
Name = "Xamarin",
Url = "http://xamarin.com/about/"
};
customMap.CustomPins = new List<CustomPin> { pin };
customMap.Pins.Add(pin);
customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(37.79752, -122.40183), Distance.FromMiles(1.0)));
}
}
}
}
But when I put the file in there it says that it doesn't exist.
Error:
FilenotfoundException
Whats the fix for this.
I tried:
file.json
but I still get the same error.Looks like the problem is how you are trying to access your json. I'm not sure(because it doesn't say) as to where are you storing it, but here the docs explain a smooth explanation as to how access stored files in a mobile phone using Xamarin Forms
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments