-2
我有錯誤我如何解決這個錯誤?
plz幫助將json轉換爲rcpts。
string json = JsonConvert.SerializeObject(rcpts);
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace sdd.Contact
{
public partial class Cantact : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void SabtButton_Click(object sender, EventArgs e)
{
WebRequest request = WebRequest.Create("http://ippanel.com/services.jspd");
string[] rcpts = new string[] { "981111111" };
string json = JsonConvert.SerializeObject(rcpts);
request.Method = "POST";
string postData = "op=send&uname=aaaa&pass=0000&message=hello Test&to=" + json + "&from=+9810001010";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
reader.Close();
dataStream.Close();
response.Close();
System.Diagnostics.Debug.WriteLine(responseFromServer);
}
}
}
謝謝你的答案 但: DeserializeObject:名稱'JsonConvert'在當前上下文中不存在plz幫助我再次 –
您需要導入'jsonConvert'。爲此,您需要安裝'Newtonsoft.Json'。「管理NuGet包」 - >搜索「newtonsoft json」。 - >點擊「安裝」。 –