Forum Cross Platform with Xamarin

How to get a json data from url and shown in mobile app?

I'm new for xamarin cross platform development. can any one show or send a code for retrieve a json data from url and show in mobile. Here i given a sample url. [click here] (,Bangladesh.json)
i want to print all city or country name from the url. Help me!

Best Answers


  • SathuSathu USMember ✭✭

    i tried to get json message from url. During that stage the problem was occured. Not possible to get json and print in the mobile app using xamarin. can u please send me a code to get json data form url and print in the mobile apps.

  • SathuSathu USMember ✭✭
    edited October 2014

    this is my code.
    static ListView listview; static Button button; public MainPage() { listview = new ListView() { RowHeight = 40 }; button = new Button() { Text = "search Again" }; var stack = new StackLayout() { VerticalOptions = LayoutOptions.FillAndExpand, Children = { button, listview }, }; this.Content = stack; GetData(); }
    async static void GetData() { WeatherReport res = new WeatherReport(); try { string contents; string Url = String.Format(""); HttpClient hc = new HttpClient(); contents = await hc.GetStringAsync(Url); res = JsonConvert.DeserializeObject<WeatherReport>(contents); listview.ItemsSource = res.list; } catch (System.Exception sysExc) { // Do something to log this error. throw; } }
    public class WeatherReport { public WeatherReport() { list = new List<WeatherReport>(); } [JsonProperty(PropertyName = "cod")] public string cod { get; set; } [JsonProperty(PropertyName = "message")] public string message { get; set; } [JsonProperty(PropertyName = "cnt")] public int cnt { get; set; } [JsonProperty(PropertyName = "list")] public List<WeatherReport> list { get; set; } }

    How to print the cod, message and cnt in listview

  • ShamnadShamnad USMember ✭✭✭

    @XamarinSnob me to have some problem with populating listview in xamarin forms. I am using the code that you given above, can you please help me to find out the my error ?

  • JoyRexJoyRex USMember ✭✭

    @GuillermoGutierrez said:
    What have you tried?

    why it is marked as an answer?

  • How can you pass data to next Activity when the List has JSON data , like passing an Id to the Next Activity

  • Joshit0Joshit0 PEMember

    How can you pass data to next Activity when the List has JSON data , like passing an Id to the Next Activity

    var nextActivity= new Intent(this, typeof(activityB));
    nextActivity.PutExtra("key", "value");

  • SreeeeSreeee INMember ✭✭✭✭✭

    Hi guys, i am new with xamarin. I want to add some json data with get web service. I try like following:

    var response = await client.GetAsync("myurl" + "?applicationid=" + applicationId + "?siteid=" + siteId + "?userid=" + 
    string responseJson = await response.Content.ReadAsStringAsync();
    Debug.WriteLine("response:>" + responseJson);

    But code not executed after get method.

    please anyone help me.

  • RamprasadKRamprasadK USMember ✭✭
    edited October 2017

    Hi @Sreeee

    Hope this helps!

    `var client = new HttpClient();
    client.BaseAddress = new Uri("http://");
    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    HttpResponseMessage response = await client.GetAsync("api/User/CheckUser?email=" + userdata.Email + "&password" + userdata.Password + "");
    if (response.IsSuccessStatusCode)
    var data = await response.Content.ReadAsStringAsync();
    var loginuserdata = JsonConvert.DeserializeObject(data);
    IsBusy = false;
    return true;

    public bool CheckUser(string email, string password)
    var user = db.Users.Where(x => x.Email == email && x.Password == password).FirstOrDefault();
    if (user != null)
    return true;
    return false;

  • hello every one,I'm new for xamarin android. help me how to get the url response.
    the response format is json

Sign In or Register to comment.