[英]How can I serialise a string array to JSON using DataContractJsonSerializer?
[英]how can i get datacontractjsonserializer to work with a string?
我有以下代碼僅在使用文件流和讀取文件時有效,如何使用json格式的字符串使它起作用?
using (FileStream stream = File.OpenRead("c://test"))
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(datastruct));
datastruct struct= (datastruct )ser.ReadObject(stream);
考慮“ 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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.