convert text to json



i use Newtonsoft.Json.Net20.dll

Html

<div id="a" runat="server">
</div>

Code

   string kb = "a";
   string b= Newtonsoft.Json.JsonConvert.SerializeObject(kb).ToString();
   a.InnerText = b;

in local host on iis6 show "a"

but on internet show

��G�[�!�{��u^Ӹ�SY�L?��qz�Z�Ŕ�?���U1k������)f�]A�(�ݣ�w N����Q�x�.�0�=�����X�y6�?��.�r�~;��[�t�~�/�K��z�|�-��W�ź��Q��&���4B��Q�4o�u��x|wrt�L�K�$���Ms�.��4��ٺ.��|�.����s����W�$��_���ӗe�54��ȯ��`�6mk�@�.*��by�ap٤Z��Oa�^�s�jӪ.��p� �n�Y>�������Ӽ͊�����n�|1~M����z�r�}�Qz�9��u��i��v���0�-ˑǃ�������/���s��t���:b�������l�~�H[�4��o'�g�/�E�=����o�� ��3G��ގ}Yߝ|�~�����H�Z�;�����i��vrg�z�m����]�Uh�Z6>[.�� )�er����I���.��.�K_yȞF(C�v�Ha>"s�4��gE����G�/a׮֓��r^5m��u�

This link

but

when use Newtonsoft.Json

       Dictionary<string, string> companyProducts = new Dictionary<string, string>();
        companyProducts.Add("product" + item.IdProduct, item.NameProduct.ToString());
        string JsonCompany = JavaScriptConvert.SerializeObject(companyProducts);

this code work fine.

this link

when site upload to internet for add new reference.Enough that copy dll to appcode

Edit

use gzip in gloabal.asax

void Application_PreRequestHandlerExecute(object sender, EventArgs e){HttpApplication app = sender as HttpApplication;string acceptEncoding = app.Request.Headers["Accept-Encoding"];Stream prevUncompressedStream = app.Response.Filter;

    if (!(app.Context.CurrentHandler is Page ||
        app.Context.CurrentHandler.GetType().Name == "SyncSessionlessHandler") ||
        app.Request["HTTP_X_MICROSOFTAJAX"] != null)
        return;
    if (acceptEncoding == null || acceptEncoding.Length == 0)
        return;
    acceptEncoding = acceptEncoding.ToLower();
    if (acceptEncoding.Contains("gzip") )
    {
        // gzip
        app.Response.Filter = new GZipStream(prevUncompressedStream,
            CompressionMode.Compress);
        app.Response.AppendHeader("Content-Encoding", "gzip");

    }
    else if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
    {
        // defalte
        app.Response.Filter = new DeflateStream(prevUncompressedStream,
            CompressionMode.Compress);
        app.Response.AppendHeader("Content-Encoding", "deflate");
    }
}

The file that you are getting from that page is a compressed file that contains an error page with an exception in it. Why it is doing this I don't know. Your global error handler might have a bug in it that causes it to send compressed data without the correct headers...

I assume you can get the file information out now you know what it is (I just right clicked on the link above and then used 7zip to open the file).

The key points though are:

Source File: c:inetpubvhostsiranfairco.comhttpdocstest.aspx.cs    Line: 20

[VerificationException: Operation could destabilize the runtime.]
   Newtonsoft.Json.JsonWriter..cctor() +6
[TypeInitializationException: The type initializer for 'Newtonsoft.Json.JsonWriter' threw an exception.]
   Newtonsoft.Json.JsonWriter..ctor() +0
   Newtonsoft.Json.JsonTextWriter..ctor(TextWriter textWriter) +16
   Newtonsoft.Json.JsonConvert.SerializeObject(Object value, Formatting formatting, JsonSerializerSettings settings) +157
   Newtonsoft.Json.JsonConvert.SerializeObject(Object value) +9
   test.Page_Load(Object sender, EventArgs e) in c:inetpubvhostsiranfairco.comhttpdocstest.aspx.cs:20
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

There is most likely something that is completely unrelated to the JSON conversion that is wrong, as not even the div tag show up in the page source.

Analysing the response in a binary editor reveals a lot of the UTF-8 sequence EF BF BD which is the character FFFD which is the Unicode replacement character. This is used when Unicode decoding fails, most likely because you have tried to decode something with the wrong encoding.

相关内容

  • 没有找到相关文章

最新更新