public static string ToJsJson(this
DataContractJsonSerializer serializer = new DataContractJsonSerializer(item.GetType());
using (MemoryStream ms = new MemoryStream())
serializer.WriteObject(ms, item);
StringBuilder sb = new StringBuilder();
sb.Append(Encoding.UTF8.GetString(ms.ToArray()));
return sb.ToString();
}
}
///
/// Json反序列化,用於接收客戶端Json後產生對應的物件
sonTo
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
T jsonObject = (T)ser.ReadObject(ms);
ms.Close();
return jsonObject;
}
🎜> }
});
代碼
代碼如下:
public class getJsonHandler: IHttpHandler
{
複製程式碼
程式碼如下:
var m_obj = { make: "Dodge", model: "Coronet R/T", Year: 1968, color: "yellow h Str = JSON.stringify(m_obj); //用Json2 .js產生Json字串
url: "postJsonHandler.ashx",
類型: 'POST',
數據: { postjson: jsonStr },
dataType: 'json',
地) },
成功:函數(結果) {
警告(結果.成功);
});
});
C# > 代碼如下:
return false;
}}
}