Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

serializing a class to json


  • Please log in to reply
2 replies to this topic

#1 Chris Seto

Chris Seto

    Advanced Member

  • Members
  • PipPipPip
  • 405 posts

Posted 29 February 2012 - 06:28 AM

I'm doing a small AJAX webserver project on my Netduino, and I need a way to convert a very large class into json, or some other serialized format for consumption on the client end. I was thinking about looking into reflections to iterate on each field contained in the class, but I'd like to see if there was any better way to handle this. The alternative is some sort of string template system, or even worse, manually creating the json string. Any ideas?

#2 H07R0D

H07R0D

    Advanced Member

  • Members
  • PipPipPip
  • 95 posts

Posted 29 February 2012 - 06:23 PM

I'm doing a small AJAX webserver project on my Netduino, and I need a way to convert a very large class into json, or some other serialized format for consumption on the client end.

I was thinking about looking into reflections to iterate on each field contained in the class, but I'd like to see if there was any better way to handle this.

The alternative is some sort of string template system, or even worse, manually creating the json string.

Any ideas?


I'm in the same boat, using a json object to control config data for my aquarium controller frontend.
The Netduino Helpers have a JSON object in them, but I believe they're currently buggy.
I pulled a JSON parser from here and modified it to compile under .NETMF 4.2 (need to flash your N+ to latest firmware) and it's got a Serialize / Deserialize.
Objects are Hashtables and ArrayLists, so not an amazing amount of overhead.

Worth trying out, depending on how big your class is. You may even want to look at an intermediate object instead of serializing a large class.

Attached Files

  • Attached File  JSON.cs   12.83KB   157 downloads


#3 Adam Clifford

Adam Clifford

    Member

  • Members
  • PipPip
  • 18 posts

Posted 12 June 2012 - 10:15 PM

This is a great, after lots of headaches with the netduino helpers library this worked great. I just removed the serializing items as i had no need for them :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.