I am just learning JSON implementation in Windows Phone 8 app
I got link of Earthquake News feeding, I want to use below link and fetch the all data to my Windows Phone app, I am completely noob in this, so please tell me how I can implement it in simple way in C# language.
Link: http://earthquake-report.com/feeds/recent-eq?json
Loading

Ramesh MaruthiPosted Jul 23, 2014, 10:31 PM
string s = Convert.ToString(e.Result);
Zia ur RehmanPosted Mar 18, 2015, 10:33 AM
http://nkishorchandra.blogspot.com/2012/10/parsing-json-in-windows-phone.html#comment-form
Ramesh MaruthiPosted Jul 24, 2014, 8:58 PM
Aditya PatilPosted Jul 24, 2014, 11:45 AM
webBrowserTask.Uri = new Uri(eop.link, UriKind.RelativeOrAbsolute);
webBrowserTask.Show();
What parameter should pass at eop.link. When I click on 1st Index of listbox, its link should open in WebBrowser, if click on 5th Data then link of 5th should get open.
Can anyone tell me the parameter so that it can take link of selected index. Please.
Aditya PatilPosted Jul 24, 2014, 11:35 AM
I Binded properly all data to the Listbox, and arranged in well mannner Atlast, the big data can be seen in the whole screen too,
I want more help now, getting stucked, When I will click on one data or value it contain one link too, I want to User should navigate to that link. How I can do that?
Ramesh MaruthiPosted Jul 24, 2014, 9:02 AM
I agree with you and I know about Json.Net before 6 months it self when I used to work with mongodb using c# yesterday I was using trail windows sdk that to 2010 so it's hard to install extended packages, I didn't find Nuget to do that anyways thanks once again it's good sharing knowledge with you and I have seen ur hard work and trouble as newbie keep going buddy all the best :)
Aditya PatilPosted Jul 24, 2014, 7:20 AM
For parsing JSON content in the Windows Phone app, there is Reference Json.NET which we can add in the references so it may be easy and least number of steps to parse JSON.
Also I heard there is SimpleJson Reference id there nwhich also can help us to parse JSON easily, no need to create Serializer and MemoryStream.
So if you want to research go for Json.NET of Newtonsoft.JSON. may be helpful for us.
Aditya PatilPosted Jul 24, 2014, 1:52 AM
Thanx @Ramesh Sir for your big help
Ramesh MaruthiPosted Jul 24, 2014, 1:50 AM
Ramesh MaruthiPosted Jul 24, 2014, 1:28 AM
Aditya PatilPosted Jul 24, 2014, 12:21 AM
Please Join me
Teamviewer details
593 940 517
6840
Ramesh MaruthiPosted Jul 24, 2014, 12:17 AM
Aditya PatilPosted Jul 24, 2014, 12:06 AM
Teamviewer details
593 940 517
6840
Aditya PatilPosted Jul 23, 2014, 9:48 PM
3257
Ramesh MaruthiPosted Jul 23, 2014, 9:32 PM
Aditya PatilPosted Jul 23, 2014, 7:43 PM
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;
ProgressBarRequest.Visibility = System.Windows.Visibility.Visible;
webClient.DownloadStringAsync(new Uri("http://earthquake-report.com/feeds/recent-eq?json"));
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
if (!string.IsNullOrEmpty(e.Result))
{
//Parse JSON result
List
>(e.Result).ToList(); ;
foreach (Earthquake q in jsondata)
{
TaskListBox.ItemsSource = new Earthquakelist { Add(new Earthquake { title = q.title, magnitude = q.magnitude, location = q.location, depth = q.depth, latitude = q.latitude, longitude = q.longitude, date_time = q.date_time, link = q.link }) };
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
ProgressBarRequest.Visibility = System.Windows.Visibility.Collapsed;
}
}
}
public class Earthquakelist : List
{ }
public class Earthquake
{
public string title { get; set; }
public string magnitude { get; set; }
public string location { get; set; }
public string depth { get; set; }
public string latitude { get; set; }
public string longitude { get; set; }
public string date_time { get; set; }
public string link { get; set; }
}
}
My Current code, Error still persist on Add,
As dzone link they added all items in
publicclassMovieList : List
Same way I tried to add all in public class Earthquakelist : List
{ }
Its shows error to jsondata
Aditya PatilPosted Jul 23, 2014, 12:41 PM
it creates new stub of Add
Ramesh MaruthiPosted Jul 23, 2014, 12:38 PM
Please try to implement in this way
http://dotnet.dzone.com/news/how-bind-data-listbox-windows
Aditya PatilPosted Jul 23, 2014, 12:35 PM
Error 2 The name 'Add' does not exist in the current context C:\Users\Aditya\Desktop\Earthquake Updates\Earthquake Updates\Earthquake Updates\MainPage.xaml.cs 37 72 Earthquake Updates
Ramesh MaruthiPosted Jul 23, 2014, 12:33 PM
}
Aditya PatilPosted Jul 23, 2014, 12:27 PM
Screenshot: http://prntscr.com/45ke4t
Error Message,
Error 2 Cannot implicitly convert type 'Earthquake_Updates.Earthquake' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?) C:\Users\Aditya\Desktop\Earthquake Updates\Earthquake Updates\Earthquake Updates\MainPage.xaml.cs 37 51 Earthquake Updates
Error Screen: http://prntscr.com/45kekh
Ramesh MaruthiPosted Jul 23, 2014, 12:21 PM
SORRY close with flower brace and try it once if not I have another idea lets c with that
Aditya PatilPosted Jul 23, 2014, 12:17 PM
Error 8 Cannot implicitly convert type 'Earthquake_Updates.MainPage.Earthquake' to 'System.Collections.IEnumerable'. An explicit conversion exists (are you missing a cast?) C:\Users\Aditya\Desktop\Earthquake Updates\Earthquake Updates\Earthquake Updates\MainPage.xaml.cs 37 51 Earthquake Updates
for below code
if (!string.IsNullOrEmpty(e.Result))
{
//Parse JSON result
List
>(e.Result);
foreach(Earthquake q in jsondata)
{
TaskListBox.ItemsSource = new Earthquake(){title = q.title, magnitude = q.magnitude, location=q.location, depth=q.depth, latitude=q.latitude,longitude=q.longitude,date_time=q.date_time,link = q.link); //Error here
}
}
Ramesh MaruthiPosted Jul 23, 2014, 12:15 PM
Aditya PatilPosted Jul 23, 2014, 12:10 PM
http://prntscr.com/45k8l5
Ramesh MaruthiPosted Jul 23, 2014, 11:22 AM
Can you paste at least 2 items from a list of result json data what your getting at that point ?
And can you give a try like this
List
>(e.Result);
Aditya PatilPosted Jul 23, 2014, 8:33 AM
I changed few code and then tried but I am not getting how to bind the data to the ListBox, so help me.
List
>(e.Result);
jsondata = JsonConvert.DeserializeObject
I changed this code of line.
My Whole code looks like this
namespace Earthquake_Updates
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;
ProgressBarRequest.Visibility = System.Windows.Visibility.Visible;
webClient.DownloadStringAsync(new Uri("http://earthquake-report.com/feeds/recent-eq?json"));
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
if (!string.IsNullOrEmpty(e.Result))
{
//Parse JSON result
List
>(e.Result);
TaskListBox.ItemsSource = jsondata;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
ProgressBarRequest.Visibility = System.Windows.Visibility.Collapsed;
}
}
}
public class Earthquake
{
public string title { get; set; }
public string magnitude { get; set; }
public string location { get; set; }
public string depth { get; set; }
public string latitude { get; set; }
public string longitude { get; set; }
public string date_time { get; set; }
public string link { get; set; }
}
}
I think jsondata getting whole data but how nto bind it with ListBox that don't know. So please solve that, and Check code too that I am right or not?
Aditya PatilPosted Jul 19, 2014, 6:05 AM
Unhandled Exception: Newtonsoft.Json.JsonSerializationException: Cannot deserial ize the current JSON object (e.g. {"name":"value"}) into type 'System.Collection s.Generic.List`1[ApiPost.position]' 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 chang e the deserialized type so that it is a normal .NET type (e.g. not a primitive t ype like integer, not a collection type like an array or List
Aditya PatilPosted Jul 19, 2014, 5:31 AM
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;
ProgressBarRequest.Visibility = System.Windows.Visibility.Visible;
webClient.DownloadStringAsync(new Uri("http://earthquake-report.com/feeds/recent-eq?json"));
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
try
{
if (!string.IsNullOrEmpty(e.Result))
{
//Parse JSON result
var root1 = JsonConvert.DeserializeObject
this.DataContext = root1;
TaskListBox.ItemsSource = root1.title;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
ProgressBarRequest.Visibility = System.Windows.Visibility.Collapsed;
}
}
}
public class Earthquake
{
public string title { get; set; }
public string magnitude { get; set; }
public string location { get; set; }
public string depth { get; set; }
public string latitude { get; set; }
public string longitude { get; set; }
public string date_time { get; set; }
public string link { get; set; }
}
}
What is wrong in Above code, I am getting below Exception.
Aditya PatilPosted Jul 19, 2014, 1:00 AM
I am completely new to JSON and parsing of it.
Ramesh MaruthiPosted Jul 18, 2014, 10:41 AM
Can you try in this way, it just an example
http://stackoverflow.com/questions/18120092/how-to-parse-the-json-data-in-windows-phone-8
http://blogs.msdn.com/b/wsdevsol/archive/2013/09/04/how-to-store-json-data-in-windows-phone-8.aspx