本文介绍了反序列化json c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助.我正在尝试反序列化json字符串(

 {"response":[259,{"body":ятебе","mid":17759,"uid":18537276,"from_id": 18537276,"date":1345466897,"read_state":1,"out":1},{"body":"jdjdjdjd","mid":17736,"uid":18537276,"from_id":18537276,"date :1345400400," read_state:1," out:1," attachment:{" type:" doc," doc:{" did:118620269," owner_id:18537276," title: "IMG_20120722_220434.jpg",大小":475878,"ext":"jpg","url":"http:\/\/vk.com \/doc18537276_118620269?hash = 59f1fe51a02a65519c& dl = 3972a9297f3da6a20c",拇指" :"http:\/\/cs4343.vkontakte.ru \/u18537276 \/-3 \/m_69a4a578da.jpg","access_key":"7a6cb6559b179dec16"}} 

)等.

这是代码:

 DataContractJsonSerializer ser =  DataContractJsonSerializer( typeof (Response_GetHistory));
Response_GetHistory gh =  Response_GetHistory();
gh =(Response_GetHistory)ser.ReadObject(stream); 


这是课程

 公共  class  Response_GetHistory
{
 public   int  s;
公共 Message []响应;
}

公共 消息
{

 public  字符串中;
公共 字符串 uid;
公共 字符串日期;
公共 字符串 read_state;
公共 字符串标题;
公共 字符串正文;
公共附件附件;
公共消息fwd_messages;
公共 字符串 chat_id;
公共 字符串 chat_active;
公共 字符串 users_count;
公共 字符串 admin_id;
公共 字符串已删除;
} 


但是反序列化失败;
我认为应该是259号..我应该在班级中更改什么?

解决方案



Please , help. I am trying to deserialize json string(

{"response":[259,{"body":"я тебе ","mid":17759,"uid":18537276,"from_id":18537276,"date":1345466897,"read_state":1,"out":1},{"body":"jdjdjdjd","mid":17736,"uid":18537276,"from_id":18537276,"date":1345400400,"read_state":1,"out":1,"attachment":{"type":"doc","doc":{"did":118620269,"owner_id":18537276,"title":"IMG_20120722_220434.jpg","size":475878,"ext":"jpg","url":"http:\/\/vk.com\/doc18537276_118620269?hash=59f1fe51a02a65519c&dl=3972a9297f3da6a20c","thumb":"http:\/\/cs4343.vkontakte.ru\/u18537276\/-3\/m_69a4a578da.jpg","access_key":"7a6cb6559b179dec16"}}

) etc.

Here is code:

DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response_GetHistory));
Response_GetHistory gh = new Response_GetHistory();
gh = (Response_GetHistory)ser.ReadObject(stream);


here is class

public class Response_GetHistory
{
public int s;
public Message[] response;
}

public class Message
{

public string mid;
public string uid;
public string date;
public string read_state;
public string title;
public string body;
public Attachments attachments;
public Message fwd_messages;
public string chat_id;
public string chat_active;
public string users_count;
public string admin_id;
public string deleted;
}


but deserialization failed;
I think becase of number 259..What should I change in my classes?

解决方案




这篇关于反序列化json c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 01:53