I am serializing to a json object using:
public static string ToJson(this object obj)
{
JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
return jsonSerializer.Serialize(obj);
}
However when I'm populating a hidden field, I'm getting the slashes with it:
"[{\"ImageLink\":\"\",\"ShowOnHomePage\":null,\"Type\...
Hi, I have a function with a List return type. I'm using this in a JSON-enabled WebService like:
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Product> GetProducts(string dummy) /* without a parameter, it will not go through */
{
return new x.GetProducts();
...
Summary: How do I map a field name in JSON data to a field name of a .Net object when using JavaScriptSerializer.Deserialize ?
Longer version: I have the following JSON data coming to me from a server API (Not coded in .Net)
{"user_id":1234, "detail_level":"low"}
I have the following C# object for it:
[Serializable]
public class Dat...
I'm using JavaScriptSerializer to serialize some entity objects.
The problem is, many of the public properties contain null or default values. Is there any way to make JavaScriptSerializer exclude properties with null or default values?
I would like the resulting JSON to be less verbose.
...
Note: I posted a similar question, which was the ancestor of this question, as I was originally thinking of using JSON.NET to parse the JSON, but I'm using the built-in deserializer, so it's a different question.
This is what I'm trying to do: I have a class called Item, for example. The json has many "elements" (if that's what they are...
[Serializable]
public class ModelResource:ISerializable
{
public Int64 Ore { get; private set; }
public Int64 Crystal { get; private set; }
public Int64 Hydrogen { get; private set; }
//needs to be ignored
public Int64 Total { get { return Ore + Hydrogen + Crystal; } }
public string ResourceType { get; private set; }
...
Ok so I'm trying to use the JavaScriptSerializer to work with this code. However it crashes when it reaches the last line;
Dim json As New String(sr.Serialize(dt))
I get this error message;
A circular reference was detected
while serializing an object of type
'System.Reflection.Module'.
I would really appreciate any insights...
I am pretty new at C# and .NET, but I've made this code to call a stored procedure, and I then want to take the returned DataTable and convert it to JSON.
SqlConnection con = new SqlConnection("connection string here");
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("getDates", con);
SqlParame...
I need to eval an JavaScriptSerializer() object.
var userSettings = '<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(ViewData["UserSettings"]) %>';
The above line gives the output as:
{"SalesTaxPercentage":7.75,"StartOfWeek":"SUNDAY","NoofRowsInList":10,"ShowDashboardEntry":5,"DisplayContactsFormat":"LastName...
Hi All,
I have a js object structured like:
object.property1 = "some string";
object.property2 = "some string";
object.property3.property1 = "some string";
object.property3.property2 = "some string";
object.property3.property2 = "some string";
i'm using JSON.stringify(object) to pass this with ajax request. When i try to deserialize ...
Hi all!
I'm developing an application in C# which can control a SqueezeboxServer(SBS). Communicating to the SBS is via JSON messages to http://serverIP:9000/jsonrpc.js
So I send JSON messages via a HTTPWepRequest and get answers via an HTTPWebResponse.
The answer I get is a String in JSON notation. And this is where the problems start....
I'm trying to read a JSON object which contains the date/time in a format that cannot be directly parsed by .NET's DateTime structure. In order to avoid having an 'int' field in my structure for the date/time, I wrote a custom DateTimeConverter:
public class DateTimeConverter : JavaScriptConverter {
public override IEnumerable<Type> S...
In ASP.NET/C#:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>
<%
JavaScriptSerializer jss = new JavaScriptSerializer();
string[] fruits = new string[3] {"apple","banana","crunchberries"};
string output = jss.Serialize(fruits);
%>
<html>
fruits=<%=output%>
</html>
returns fruits=["apple","banana","c...
I'm having trouble getting the JavascriptSerializer to deserialize an array of objects. I'm not terribly sure what I'm missing.
Here's my object...
public class HomefinderResult
{
public Data data;
public List<Listing> listings;
public Status status;
public class Listing
{
public string recordingDate;
...
Hello,
I am using Flexigrid in my project to add a button on the grid toolbar I can use code like this:
...
"buttons":[
{"name":"Modifica","bclass":"edit","onpress":"doCommand"},
{"name":"Elimina","bclass":"delete","onpress":"doCommand"}
],
...
Anyway the "onpress" attribute shall contain a reference to a js callback and ...
"responseCode": String
"responseMessage": String
"responseBody": { "conversations": [
{
"conversationId": String,
"state": String,
"conversationType": String,
"mediaType": Enum,
"startDate":Integer,
"duration": Integer,
"tags":[{ "tagName":String,
"tagType":String,
"tagCreateDate":Integer,
"tagOffset":Integer
}],
]}
This s...
I am serializing a complex object with lot of properties of other Types and Lists to JSON form but the issue is with DateTime properties. I get the epoch time with JavascriptSerializer (rather than mm/dd/YYYY).
Is there any way I can get the datetime in mm/dd/YYYY : HH.MM.SS form without modifying the class defination of the object i a...