Solved

how do i serialize this json in c#?

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

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
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 74

Expert Comment

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

10 Experts available now in Live!

Get 1:1 Help Now