【发布时间】:2014-03-21 11:20:23
【问题描述】:
我是 C# Windows Phone 编程的初学者。我正在开发一个应用程序,在该应用程序中,我使用 Web 客户端从站点获取 JSON 响应,但我不知道如何解析它。
你能帮我解决这个问题吗?
代码:
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void btnRefreshTweets_Click(object sender, RoutedEventArgs e)
{
string winPhoneGeekTweetsUrl = @"http://ffff.xxxx.nxt/wpjson.php";
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri(winPhoneGeekTweetsUrl));
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
{
return;
}
MessageBox.Show(e.Result );//-->this is where JSON response is displayed
}
}
wpjson.php
<?php
mysql_connect("mysql2.000webhost.com","12345","12345");
mysql_select_db("a1111111_forms");
$sql=mysql_query("SELECT * FROM newstable");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
echo json_encode($output);
?>
我还希望它显示在列表中。
【问题讨论】:
标签: c# json visual-studio-2012 windows-phone-8