Solved

how do i serialize this json in c#?

Posted on 2015-01-14
3
109 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 42
VS2013 publish C# application Created folder -- where is it??? 10 32
how to remove duplicate code from my project 5 49
WPF Select Items 3 27
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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