dsjpqpdm620596 2015-03-22 07:17
浏览 501
已采纳

如何在wpf应用程序中使用json响应

My wpf application is communicating with php web api. First I post some data to web api and recieved json resonse. At server side php script just prepared an array and json_encode(arrayName)is sent to client. At my client side I am using following code

using (WebResponse jsonResponse = request.GetResponse())
            {
                // Do something with response
                StreamReader streamReader = new StreamReader(jsonResponse.GetResponseStream());
                String responseData = streamReader.ReadToEnd();

                MessageBox.Show(responseData);
            }

in the message box I am able to see all the data sent by server. Now I don't have any idea how to assign this data to local variables? Kindly guide me.

http://i.imgur.com/1Qzds8G.png

EDIT

Response shown in message box is :-

[{"response":"true","user_id":"250","username":"sapan108"}]'

After Googling I created following class :-

public class UserData
{
    public string response { get; set; }
    public string error { get; set; }
    public int user_id { get; set; }
    public string username { get; set; }
}

Now How to assign json response to these variables.

Note: Due to less reputation unable to post image directly. Sorry for inconvenience.

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 从零开始汽车自动驾驶相关的软件学习
      • ¥30 操作系统进程实验虚拟机
      • ¥15 yolov5摄像头识别只能检测第一帧图像
      • ¥15 有没有可以下载钉钉群文件视频的软件
      • ¥15 如何用LaTeX打出如下的表格
      • ¥15 程序填空补充完整的代码一共三题
      • ¥15 在MySQL中使用while建表,报错
      • ¥15 python导入pyautogui报错,网上也没有找到解决方法如何解决?
      • ¥15 关于IPSEC和NAT SERVER同时使用的情况下,该如何解决客户端访问服务器的问题
      • ¥15 eclipse项目在idea运行部署到云服务器