SoFunction
Updated on 2025-03-06

Analysis of examples of converting objects and JSON strings in C# programming

This article analyzes the method of converting objects and JSON strings into each other in C# programming. Share it for your reference, as follows:

DoNet2.0 needs to be used

The code is as follows:

using System;
using ;
using ;
using ;
namespace 
{
  public class JsonTools
  {
    // Generate a Json string from an object information    public static string ObjectToJson(object obj)
    {
      return (obj);
    }
    // Generate object information from a Json string    public static object JsonToObject(string jsonString, object obj)
    {
      return (jsonString, ());
    }
  }
}

Donet3.5 comes with DLL processing json string

Note the quote:

The code is as follows:

using System;
using ;
using ;
using ;
using ;
using ;
using ;
namespace 
{
  public class JsonTools
  {
    // Generate a Json string from an object information    public static string ObjectToJson(object obj)
    {
      DataContractJsonSerializer serializer = new DataContractJsonSerializer(());
      MemoryStream stream = new MemoryStream();
      (stream, obj);
      byte[] dataBytes = new byte[];
       = 0;
      (dataBytes, 0, (int));
      return Encoding.(dataBytes);
    }
    // Generate object information from a Json string    public static object JsonToObject(string jsonString, object obj)
    {
      DataContractJsonSerializer serializer = new DataContractJsonSerializer(());
      MemoryStream mStream = new MemoryStream(Encoding.(jsonString));
      return (mStream);
    }
  }
}

I hope this article will be helpful to everyone's C# programming.