JSON-RPC给出400错误和NaN值错误显示在 - JsonConvert.DeserializeObject <jobject>

时间:2018-03-27 13:16:35

标签: c# json websocket json.net json-rpc

在JSON-RPC中如果运行下面的源代码,它将显示错误或NaN结果,它不会返回JSON对象字符串作为响应。

我已手动创建了一个类并设置了idcommand,然后对其进行了序列化,但我不确定为什么会出现错误我有很多更改,但没有得到好的结果。< / p>

我不确定我忘记了什么,并且正在努力让它按预期工作。

我的预期结果是:{ "id": 1, "status": "success", "type": "response", "result": {} }

namespace JsonRpcRipple
{
public class RipTest
{
    public int id { get; set; }
    public string command { get; set; }
}
public partial class Default : System.Web.UI.Page
{

    public JObject InvokeMethod()
    {
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("http://s1.ripple.com:51234/");

        webRequest.ContentType = "application/json-rpc";
        webRequest.Method = "POST";

        RipTest joe = new RipTest();
        joe.id = 1;
        joe.command = "ping";
        string s = JsonConvert.SerializeObject(joe);

        // serialize json for the requestf
        byte[] byteArray = Encoding.UTF8.GetBytes(s);
        webRequest.ContentLength = byteArray.Length;

        try
        {
            using (Stream dataStream = webRequest.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
            }
        }
        catch (WebException we)
        {
            //inner exception is socket
            //{"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 23.23.246.5:8332"}
            throw we;
        }

        WebResponse webResponse = null;
            try
            {
                using (webResponse = webRequest.GetResponse())
                {
                    using (Stream str = webResponse.GetResponseStream())
                    {
                        using (StreamReader sr = new StreamReader(str))
                        {
                            return JsonConvert.DeserializeObject<JObject>(sr.ReadToEnd());
                        }
                    }
                }
            }
            catch (WebException webex)
            {

                using (Stream str = webex.Response.GetResponseStream())
                {
                    using (StreamReader sr = new StreamReader(str))
                    {
                        var tempRet = JsonConvert.DeserializeObject<JObject>(sr.ReadToEnd());
                        return tempRet;
                    }
                }

            }
            catch (Exception)
            {

                throw;
            }

    }

    protected void Page_Load(object sender, EventArgs e)
        {

         var ret = InvokeMethod();
        Response.Write(ret);

        }

    }
}

0 个答案:

没有答案