C#部分
[C#] 纯文本查看 复制代码 using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
namespace CSharpToE
{
public static class CSToE
{
[DataContract]
public class Person
{
[DataMember]
public string Name { get; set; }
[DataMember]
public int Age { get; set; }
}
[DllExport]
public static IntPtr aa()
{
string json = "";
Person person = new Person { Name = "Alice", Age = 30 };
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Person));
using (MemoryStream ms = new MemoryStream())
{
serializer.WriteObject(ms, person);
json = Encoding.GetEncoding("GB2312").GetString(ms.ToArray());
}
return Marshal.StringToHGlobalAnsi(json);
}
}
}
易语言
|