我有以下代码,只有在使用文件流和读取文件时才有效,如何使用json格式的字符串使其工作?
using (FileStream stream = File.OpenRead("c://test"))
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(datastruct));
datastruct struct= (datastruct )ser.ReadObject(stream);
答案 0 :(得分:0)
考虑“json”是你的字符串:
var ms = new MemoryStream();
var sw = new StreamWriter(ms);
sw.Write(json);
sw.Flush();
ms.Position = 0;
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Item));
var type = ser.ReadObject(ms);