我如何修复此错误?

时间:2017-08-13 16:25:21

标签: asp.net

我的错误

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);

        }
    }
}




1 个答案:

答案 0 :(得分:0)

您可以尝试ParseDeserializeObject

JObject json = JObject.Parse(rcpts);

或者

dynamic json  = JsonConvert.DeserializeObject(rcpts);