0
我想解析JSON到一個對象,但它保持失敗。解析JSON到對象失敗
我不斷收到錯誤:
The type or namespace name 'DataContractJsonSerializer' does not exist in the namespace 'System.Runtime.Serialization.Json' (are you missing an assembly reference?)
但到目前爲止,所有引用已被添加,但不知何故,它仍然無法正常工作。
我在這裏做正確的事情嗎?
我到目前爲止的代碼如下:
public Json_Connection()
{
// Create a request for the URL.
WebRequest request = WebRequest.Create (
"http://10.190.80.248/WebService/webservice.asmx/getStudentID?id=1");
// If required by the server, set the credentials.
request.ContentType = "application/json";
request.Credentials = CredentialCache.DefaultCredentials;
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams and the response.
XmlSerializer serializer = new DataContractJsonSerializer (Json.GetType(), new Type[] { typeof(Json) });
Json flippo = (Json)serializer.Deserialize (reader);
}
我使用的是MAC,所以沒有窗戶的文件夾或.net這個MAC