如何在C#中使用json_decode [英] How can use json_decode in C#

查看:395
本文介绍了如何在C#中使用json_decode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在mysql数据库中我有custom_field,它有类似这样的数据;



in mysql database i have custom_field that have some sort of data like this;

{"1":"product","2":"111111"}



i找到json viewer



JSON Viewer [ ^ ]



它解码上面的数据,但当我看第二行时像


i have found json viewer

JSON Viewer[^]

and it decodes the data above but when i look the second row like

a:4:{i:1;s:9:"product";i:3;s:10:"6120359453";i:4;s:0:"";i:5;s:12:"company";}



这是未解码的,它说的格式不正确。它是一种解码这些数据的方法像json viewer一样的代码。



谢谢。



我的尝试:



i试过这个:1:{i:4; s:11:12772044120;}在unserialize.com这是我喜欢的工作知道这个字符串是否可以在c#中反序列化,如


this is not decoded it says not in proper format.is it a way to decode this data using the same codes like json viewer.

thanks.

What I have tried:

i have tried this a:1:{i:4;s:11:"12772044120";} at unserialize.com this is working i like to know if is this string can be deserialize in c# like

JavaScriptSerializer js = new JavaScriptSerializer();

            try
            {
                Dictionary<string, object> dic = js.Deserialize<Dictionary<string, object>>(txtInput.Text);

                TreeNode rootNode = new TreeNode("Root");
                jsonExplorer.Nodes.Add(rootNode);
                BuildTree(dic, rootNode);
            }
            catch (ArgumentException argE)
            {
                //MessageBox.Show("JSON data is not valid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }





或者服务器上的php反序列化页面,但我听说这对安全性不是一个好主意,而print_r所以我可以调用c#application来自网页,例如



or maybe a php unserialize page at server but i heard it was not a good idea for security, and print_r so i can call in to c# application from web page like

WebClient wc = new WebClient();
            var json = wc.DownloadString(textBox1.Text);

            List<User> users = JsonConvert.DeserializeObject<List<User>>(json);

            dataGridView1.DataSource = users;





任何想法请帮忙谢谢。



any idea please help thanks.

推荐答案

这不是有效的JSON格式数据。我不知道它是什么。



你将不得不回到这些数据的来源,找出格式是什么。
That's not valid JSON formatted data. I don't know what it is.

You're going to have to go back to whatever site this data is coming from and find out what the format is.


引用:

如何在C#中使用json_decode

How can use json_decode in C#

要使用json解码,首先要使用需要有json数据,这是强制性的。你的数据看起来像json的事实没有帮助。



要么你找到什么是数据格式并找到解码器,你要么建立自己的解码器。别无选择。

To use json decode, you first need to have json data, it is mandatory. The fact that your data loosely look like json don't help.

Either you find what is the data format and find a decoder, either you build your own decoder. No other choice.


非常感谢你的回答,

i试过这个:1:{i:4; s:11:12772044120 ;}在unserialize.com这是有用的我想知道这个字符串是否可以在c#中反序列化像

Thank you very much for your answers,
i have tried this a:1:{i:4;s:11:"12772044120";} at unserialize.com this is working i like to know if is this string can be deserialize in c# like
JavaScriptSerializer js = new JavaScriptSerializer();

            try
            {
                Dictionary<string, object> dic = js.Deserialize<Dictionary<string, object>>(txtInput.Text);

                TreeNode rootNode = new TreeNode("Root");
                jsonExplorer.Nodes.Add(rootNode);
                BuildTree(dic, rootNode);
            }
            catch (ArgumentException argE)
            {
                //MessageBox.Show("JSON data is not valid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }





或者服务器上的php反序列化页面,但我听说这对安全性不是一个好主意,而print_r所以我可以调用c#application来自网页,例如



or maybe a php unserialize page at server but i heard it was not a good idea for security, and print_r so i can call in to c# application from web page like

WebClient wc = new WebClient();
            var json = wc.DownloadString(textBox1.Text);

            List<User> users = JsonConvert.DeserializeObject<List<User>>(json);

            dataGridView1.DataSource = users;





任何想法请帮忙谢谢。



any idea please help thanks.


这篇关于如何在C#中使用json_decode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆