C#/Json.net/我如何反序列化消息? [英] C# / Json.net / how can i deserialize the message?
问题描述
请帮助我下一步需要做什么?我需要此消息位于其专用字符串中 但我不知道该怎么做
please help me on what i need to do next? i need this message to be inside their dedicated strings but i got no idea how to do it
还有使用字典吗?
我收到的消息是这个.它在名为sServerResponse的字符串中
the message that i receive is this.. its inside a string called sServerResponse
{"pcname": "Kat", "pause": [], "ip": "192.168.1.100", "paused": 0, "services": [], "session": "", "shop": [], "end": 0, "used": 0, "start": 0, "timeup": 0, "follow": "sui", "consq": {"1": "basic", "3": "rounding", "2": "minimum"}, "stas": 0, "price": 0, "pc_status": 1, "account_details": {"3": "Member", "2": "Staff/Member", "4": "Timecode"}, "msg": "Connection/Update accepted.", "mac": "00112233445", "others": [], "remarks": "", "ticker": {"units": 1}, "fixed_time": [], "account": "", "pause_tmp": {"s": 0, "e": 0}, "ver": {}, "status_details": {"1": "Idle", "0": "Offline", "5": "Fixed", "4": "Open", "7": "Mem", "6": "Extended", "8": "Timecode"}, "cmd": "nothing", "load": 0, "deposit": [], "data": {"fixed": [], "open": 0}, "restirctions": {"start_button": 0, "keys": [{"ctrl-esc": 0}, {"alt-tab": 0}], "mouse": 1, "drives": [{"c": 0}, {"d": 0}], "desktop": 0, "task_manager": 0, "keyboard": 1, "taskbar": 0, "control_panel": 0}}
请引导我..我已经阅读了无数的Google IVE和主题. json.net上的示例甚至无法正常工作
please guide me.. countless googles ive made and topics i have read. the sample on json.net didnt even work
编辑/更新:
我正在尝试这个
List<WrapperReader> datas;
datas = new JavaScriptSerializer(new SimpleTypeResolver()).Deserialize<List<WrapperReader>>(jsonInput);
}
但是数据为空,这可能是什么问题?
but datas is empty, what may be the problem here?
更新2
我想出什么来弄错了
上课.
如果我要接收一个字符串数组.然后在我的类中,我必须将其声明为数组 小数点和日期也一样
if im going to receive a array of strings . then inside my class i must declare it as array to same goes to decimals and dates
关于日期..如果我要接收日期.我如何声明它以便包含日期?
about dates.. if im going to receive a date. how do i declare it so it can contain a date?
我要完成编码,看看是否真的是罪魁祸首
im going to finish the coding see if its really the culprit
推荐答案
您好
我为您编写了一个基本示例.
您可以在没有Json.NET库的情况下使用.
Hi
I wrote a basic example for you.
You can use without Json.NET library.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
namespace ConsoleApplication1
{
public class Customer
{
public int CustomerID { get; set; }
public string CustomerName { get; set; }
public string CustomerSurname { get; set; }
public override string ToString()
{
return this.CustomerID + " " + this.CustomerName + " " + this.CustomerSurname;
}
}
class Program
{
static void Main(string[] args)
{
string JSonData = @"[
{
""CustomerID"": ""1"",
""CustomerName"": ""Mehmet"",
""CustomerSurname"": ""Tasköprü""
},
{
""CustomerID"": ""2"",
""CustomerName"": ""Cin"",
""CustomerSurname"": ""Ali""
},
{
""CustomerID"": ""3"",
""CustomerName"": ""Temel"",
""CustomerSurname"": ""Reis""
}]";
IList<Customer> iListData = new JavaScriptSerializer().Deserialize<IList<Customer>>(JSonData);
foreach (var item in iListData)
Console.WriteLine(item.ToString());
Console.Read();
}
}
}
这篇关于C#/Json.net/我如何反序列化消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!