Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
in mysql database i have custom_field that have some sort of data like this;

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

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";}

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
C#
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);
            }


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
C#
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.
Posted
Updated 15-May-16 8:31am
v3
Comments
Sergey Alexandrovich Kryukov 12-May-16 15:22pm    
Not clear. After all, convert it to whatever you want. What prevents you from doing so?
—SA
Richard Deeming 12-May-16 15:24pm    
That is not a valid JSON string. You need to find out what format it's supposed to be it, and find or write code to parse it.

If it's supposed to be JSON, then find the person who wrote the code that produces it, point them to the official JSON site[^], and tell them to do it again properly.

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.
 
Share this answer
 
Quote:
How can use json_decode in C#
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.
 
Share this answer
 
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
C#
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);
            }


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
C#
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.
 
Share this answer
 
Comments
Patrice T 14-May-16 15:24pm    
Don't use a Solution to ask a question, almost nobody will notice.
Use Improve question to update your question.
Quote:
is it a way to decode this data using the same codes like json viewer.
As I understand it is a question (no question mark set). Then I have only two answers:

No. No, because your format does not comply JSON standard and you cannot directly use JSON libraries here.

Yes. Yes, because you can study sources of JSON Viewer and change codes of this library to read your custom format. But it is not easy way, because need meeting to the license and study of your custom format. You can also study other parsers. So, I think if you understand how JSON Viewer and JSON parsers work, you can find a solution. The key is understanding how parsers work.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900