跳到主要內容

發表文章

目前顯示的是有「JSon」標籤的文章

[JQuery] ajaxfileUpload.js return JSON format Error

在調整asp.net MVC上傳程式的時候, 發現actionresult return JSON時候,會出現下面的錯誤 SyntaxError: Unexpected token < 仔細查了一下,才發現 Retrun回來的JSON,不是單純的JSON資料而已 還被加上了<pre ......的資料 所以回傳回來後javascript接到就認為格式不正確。 主要原因出在ajaxfileupload.js 的一個判斷上 uploadHttpData: function(r, type) { var data = !type; data = type == "xml" || data ? r.responseXML : r.responseText; // If the type is "script", eval it in global context if (type == "script") jQuery.globalEval(data); // Get the JavaScript object, if JSON is used. if (type == "json") eval("data = " + data); // evaluate scripts within html if (type == "html") jQuery("<div>").html(data).evalScripts(); return data; } 只要將原本的 if (type == "json") eval("data = " + data); 修改成 if (type == "json"){ if (data.inde...

[JSON] asp 中 decode JSON的方法

可以藉由Javascript來處理   <script language="JScript" runat="Server"> function toObject(json) { eval("var o=" + json); return o; } </script> <% Dim json json = "{'poid':'1','username':'abc','email':'user@gallerymax.net'}" Set json = toObject(json) Response.Write json.poid & "<br/>" Response.Write json.username & "<br/>" Response.Write json.email & "<br/>" Set json = Nothing %>

[asp.NET]JSON Deserialize

在.net中有提供一個JSON的物件可以做JSON的serialize跟Deserialize, 要做deserilize可以把json 的字串轉.net中的物件 一般一維的json物件可以直接轉成 dictionary(of string,string)來存放 如下面的code Dim jsonString As String = " {'Name': 'Jason','Title':'Mr,','Age':'25'}" Dim JSONSerializer As New System.Web.Script.Serialization.JavaScriptSerializer() Dim JSON_obj = JSONSerializer.Deserialize(Of Dictionary(Of String, String))(jsonString) 陣列物件可以轉成list(of dictionary(of string,string))來存放 Dim jsonString As String = " [{'Name': 'Jason','Title':'Mr,','Age':'25'},{'Name': 'John','Title':'Mr,','Age':'55'}]" Dim JSONSerializer As New System.Web.Script.Serialization.JavaScriptSerializer() Dim JSON_obj = JSONSerializer.Deserialize(Of Dictionary(Of String, String))(jsonString) 比較複雜的物件,則可能需要自行建立一個class來作為存放的依據 Public Class jsonobj Property Name() As String Pr...

[Web Service] Web service return json

Webservice 要output JSON格式的資料 在web service中 method 要加上 [ScriptMethod(ResponseFormat:=ResponseFormat.Json)] _ class 要先設定[ScriptService()] 這樣Jquery.ajax才能使用 [web service] Imports System.Net Imports System.IO Imports System.Web.Services Imports System.Web.Services.Protocols Imports System.Web.Script.Services Imports System.ComponentModel Imports net.gallerys.common.util Imports PLaiN.dll Imports log4net Imports Newtonsoft.Json <System.Web.Services.WebService(Namespace:="http://tempuri.org/")>_ <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <ToolboxItem(False)> _ <ScriptService()> _ Public Class WebService Inherits System.Web.Services.WebService <WebMethod()> _ Public Function HelloWorld() As String Return "Hello World" End Function <WebMethod()> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _ Function Li...

[ASP.net] Useful JSON Library:Json.NET

How to use it's very Simple:   Dim json As New JsonSerializer()   json.NullValueHandling = NullValueHandling.Ignore   Dim sb As New StringBuilder   Dim sw As New IO.StringWriter(sb)   Dim jw As New JsonTextWriter(sw)   json.Serialize(jw, ObjectToJson )   Response.Write(sb.ToString) Download JSon.net