Solved

how do i serialize this json in c#?

Posted on 2015-01-14
3
103 Views
Last Modified: 2015-01-15
hello sir,i dont know how to serialize the following json

{"HashParams":{"YYBH":"113001","FN":"SP3_3002","JBR":"001","SESSIONID":"113001:2a660fe1-ac25-4d44-8ab0-a7d38e6d254a"},
"DataPackage":
{"ZYCFXMDR":
[{"YYXMBM":"011131","CFXMWYH":"222"},
  ]
}

im confusing the "ZYCFXMDR",if without the "ZYCFXMDR",i could use such CLASS & use the json.net to serialize it

public class HashParams
{
  pulbic string YYBH {get;set;}

  pulbic string FN {get;set;}

  pulbic string JBR {get;set;}

pulbic string SESSIONID {get;set;}

public iList<DataPackage> {get;set;}
 
}

public class DataPackage
{
  public string  YYXMBM  {get;set;}

public string  CFXMWYH {get;set;}
}
then i serialize it in JSON.NET

if without the "ZYCFXMDR",i could do something like the following
string output = JsonConvert.SerializeObject(HashParams),however i dont know what to do if "ZYCFXMDR" exists

best regrads
ken
0
Comment
Question by:ken yup
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40549849
Have you looked at http://json2csharp.com/ yet? It seems pretty good at transforming JSON structure into C# class structure (see attached).
Untitled.png
0
 

Author Comment

by:ken yup
ID: 40551154
thanks,i apperciate it,however the tools is not good enough,becuase it cant parse my json
 Parsing your JSON didn't work. Please make sure it's valid.
Already did that? Please let me know so I can fix it.
but with your tips,i have found this tools,it's useful
https://jsonclassgenerator.codeplex.com/
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40551251
Your JSON appeared to be missing a closing curly brace. When I added that in, the JSON parsed fine.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Entity Framework Error: 'The user instance login flag is not supported' 12 32
bulid json format 3 46
XAML: Layout 8 25
Class object 2 27
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now