Solved

how do i serialize this json in c#?

Posted on 2015-01-14
3
105 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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