Jim van Gulik

Json Serialization With .net Typenamehandling

Recommended Posts

Hi,

 

I am testing Fusion Charts with JSON serialization. The data required by Fusion Charts is (for example):

 

{
"chart":
{"lowerlimit":"0","upperlimit":"100","lowerlimitdisplay":"Bad","upperlimitdisplay":"Good","numbersuffix":"%","showvalue":"1"},
"colorrange":
{"color":[
{"minvalue":"0","maxvalue":"75","code":"FF654F"},
{"minvalue":"75","maxvalue":"90","code":"F6BD0F"},
{"minvalue":"90","maxvalue":"100","code":"8BBA00"}
]
},
"dials":{"dial":[{"value":"92"}]}}

 

 

I have created a ChartData class with a Chart property and a collection List<Color> ColorRange; When I serialize the data, this is the result:

 

{
"chart":{"lowerlimit":"0","lowerlimitdisplay":"bad","numbersuffix":"%","showvalue":"1","upperlimit":"100","upperlimitdisplay":"good"},
"colorrange":[
	{"code":"ff654f","maxvalue":"75","minvalue":"0"},
	{"code":"f6bd0f","maxvalue":"90","minvalue":"75"},
	{"code":"8bba00","maxvalue":"100","minvalue":"90"}
]
}
....

 

The problem is that .NET doesn't serialize the "color" TypeName. I have been looking at standard .NET and I even have been testing JSON.NET, but I can't seem to make this work.

 

So I need:

"colorrange":{"color": {"code":" ...

 

Instead of:

 

"colorrange":[
{"code":"ff654f","

 

Do you have a sample code or application where .NET is used to provide Fusion Charts with JSON data?

 

Thanks in advance

Jim

Edited by Jim van Gulik

Share this post


Link to post
Share on other sites

Hi,

 

Hi,

 

I am testing Fusion Charts with JSON serialization. The data required by Fusion Charts is (for example):

The problem is that .NET doesn't serialize the "color" TypeName. I have been looking at standard .NET and I even have been testing JSON.NET, but I can't seem to make this work.

 

So I need:

"colorrange":{"color": {"code":" ...

 

Instead of:

 

"colorrange":[
{"code":"ff654f","

 

Do you have a sample code or application where .NET is used to provide Fusion Charts with JSON data?

 

Thanks in advance

Jim

 

Could you please let us know the Chart Type that you are using so that we are able to assist you with a sample using ASP.Net and JSON data?

 

Awaiting your reply.

Share this post


Link to post
Share on other sites
1360916138[/url]' post='52113']

Hi,

 

Could you please let us know the Chart Type that you are using so that we are able to assist you with a sample using ASP.Net and JSON data?

 

Awaiting your reply.

It's a very basic Line chart.

 

A sample would be great, thanks!

Share this post


Link to post
Share on other sites

Hi,

 

It's a very basic Line chart.

 

A sample would be great, thanks!

 

Please check with the attached "LineChartJSON" sample attached with this post.

 

Also, please refer to the following links for details on the JSON data format that FusionCharts currently supports. You would need to use only this format in order to feed JSON data to the chart.

Ref.- http://docs.fusioncharts.com/charts/contents/?DataFormats/JSON/Overview.html

http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/csnet/CS_BasicExample.html#json

 

Hope this helps. :)

LineChartJSON.zip

Share this post


Link to post
Share on other sites

Hi,

 

Hope this helps. :)

Thanks for the effort!

 

Although this wasn't really what I meant. You have provided an example where the JSON data is read from a file.

 

My problem occured with JSON serialization (from a webservice or MVC controller).

 

However, I have managed to get it to work. I have added some extra properties which resulted in the correct JSON format.

Thanks anyway!

 

Regards,

Jim

 

 

 

Share this post


Link to post
Share on other sites

Hi Jim,

 

Thanks for the effort!

 

Although this wasn't really what I meant. You have provided an example where the JSON data is read from a file.

 

My problem occured with JSON serialization (from a webservice or MVC controller).

 

However, I have managed to get it to work. I have added some extra properties which resulted in the correct JSON format.

 

Thanks anyway!

 

Regards,

Jim

 

 

 

 

Glad that your issue is resolved. :)

 

Happy FusionCharting! :)

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now