.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
MarieAdela
Imran Ghani
Post New Web Links

How to get Datetime From Json Object.

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :ASP.Net
 

Hi All

 I am calling an action from JQuery using $.getJSON() method.

This action returns a JsonResult object.

I am getting all the values correctly but not the Date Format.

Below is the Date format which i am getting.

/Date(1287587195000)/

/Date(1287587195000)/


But i want it like "10/15/2010 11:56 AM" this format.

How can i achieve it.....Please Help




View Complete Post


More Related Resource Links

JSON Deserialize into Entity Framework Object and setting the DataMemberAttribute "Name="

  

Hi,

 

I'm in the process of deserializing a JSON object into an Entity Framework object.  The property names in the JSON do not match up totally with the property names in the Entity Framework Objects. What I'd like to do is set "Name=" on the  "DataContractAttribute" for the table and the "DataMemberAttribute" for the properties in the Designer.cs file.  I tried setting these in the Designer.cs file manually just to see if it would work - which it did (using JSON.Net) but of course when I went into the .edmx designer I lost all my changes.  Is there a way to do this?

 

Thanks in advance


Deserialize JSON object in C#

  
Hi, I am new to JSON and one of my service is returning JSON object as a string to my application. I need to Deserialize JSON object in C#. My JSON string is in the current format. string str = "{\"candidates\":[{\"address\":\"1580 MARKET ST, SAN FRANCISCO, CA, 94102\",\"location\":{\"x\":-122.42054,\"y\":37.7745960000001},\"score\":40,\"attributes\":{}},{\"address\":\"1576 MARKET ST, SAN FRANCISCO, CA, 94102\",\"location\":{\"x\":-122.420355,\"y\":37.7747030000001},\"score\":40,\"attributes\":{}}]}"; Can anyone please help me how to get all the address, locations, score and attributes from the above string. Thankyou, Ravi.

Create a datetime object as dd/mm/yyyy

  
Hi i want to create a datetime object in the way dd/mm/yyyy but the defualt behaviour of datetime object is mm/dd/yyyy. I want this because my user enters date in dd/mm/yyyy format and i want to apply different additions and subtrations on this format. I know how to display dates in different formats. 

How to use return JSON object from web service as a declared Type?

  
Hi, I just hit the following issue: I am calling a web service that returns a serialized JSON object let's say: __type, FirstName, LastName (.net object Person with properties FirstName and LastName). __type's value is Test.Person I have created a JS object using Type.registerNameSpace/registerClass called Demo.Person and it is registered on the page using the ScriptManager. Everything is working fine; I am able to get data from the server on the call back. Is it possible to make the returned object from the web service be an instance of the declared JavaScript Demo.Person class? The idea would be to call a method like result.getFullName() on the client side without having to copy all the properties. This is just a simple scenario for more complex objects.   Thanks,   Teo

Xml deserialization of a Nullable DateTime object

  

Morning, we've had this a lot but the answers I've found do not appear to work.

 

C# 3.0, .Net 3.5, XML Serialization into a nullable DateTime property does not work with an empty string.  The exception is thrown before the internals of the property, when the XmlSerializer attempts to use DateTime.ParseExact (when I use a DataType="date" value) and just complains that it is not a valid DateTime format when I do not.

A few of the various combinations of signature that I have used are below but am I fundamentally wrong that empty strings should be classed as null values?  I bet at the end of this the conclusion will be: "if you have a value then pass a populated element in the xml, if you don't then don't pass that element at all" or "if you have no value you can still send the element so long as it has the xsi:nil attribute" .

A few combinations:

[XmlElement("foo")]

DateTime Foo {get; set;}

 

[XmlElement("foo")]

DateTime? Foo {get; set;}

 

[XmlElement("foo", DataTime="date")] // yes I just want the date part

DateTime? Foo {get; set;}

 

[XmlElement("foo", IsNullable=true)] // I believe Bet that this onl

Xml deserialization of a Nullable DateTime object

  

Morning, we've had this a lot but the answers I've found do not appear to work.

 

C# 3.0, .Net 3.5, XML Serialization into a nullable DateTime property does not work with an empty string.  The exception is thrown before the internals of the property, when the XmlSerializer attempts to use DateTime.ParseExact (when I use a DataType="date" value) and just complains that it is not a valid DateTime format when I do not.

A few of the various combinations of signature that I have used are below but am I fundamentally wrong that empty strings should be classed as null values?  I bet at the end of this the conclusion will be: "if you have a value then pass a populated element in the xml, if you don't then don't pass that element at all" or "if you have no value you can still send the element so long as it has the xsi:nil attribute" .

A few combinations:

[XmlElement("foo")]

DateTime Foo {get; set;}

 

[XmlElement("foo")]

DateTime? Foo {get; set;}

 

[XmlElement("foo", DataTime="date")] // yes I just want the date part

DateTime? Foo {get; set;}

 

[XmlElement("foo", IsNullable=true)] // I believe Bet that this onl

JSON string to Object

  

If I have a  string  containing  valid JSON

how can I conver to an obect in c#?


Bind Repeater Control with JSON object

  

I have dropdown in the aspx page. I am calling JQuery on dropdown chnage and JQuery is calling GenericHandler.ashx . The Handler is retuns 

Serialize JSON  string. I ned to bind  my Repeater control with this JOSN object any can have idea . could you please help fro me. here I am giving  my sample aspx page code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>

<script type="text/javascript"  src="Shared/jquery-1.4.2.js" ></script>
<script type="text/javascript">
$(document).ready(function(){
  $("#ddlPaging").change(function(){
    var _entityId = 1;
    var _rowCount  = 5;
  var _pageIndex  = 8;
 
 

MVC3 + How to pass JSON Object as dictionorary object

  

In MVC3 Beta version i have action result same like

public ActionResult Save(Dictionary<string, string> dicObject)

 

I want to pass JSON Object in POST Method from javascript and need to get as dictionoray object

 

How can i do this? can you write example if possible?

 

Its urgent, please hep me

 

Thanks

 


Problem in passing Json collection object from View to Action

  

Hi,

I am trying to send json data from view to controller action.  But the issue is the data is not populating in the action parameter List<Score>.

View Model:
public class Score
{
   public int QuestionId { get; set; }
   public int PrevAnswerId { get; set; }
   public int CurrAnswerId { get; set; }
   public string CurrAnswerName { get; set; }
}


Json Data look like:
[
{QuestionId:1, PrevAnswerId:3,  CurrAnswerId:3,  CurrAnswerName:'Known to Broker'},
{QuestionId:2, PrevAnswerId:7,  CurrAnswerId:7,  CurrAnswerName:'Completed'},
{QuestionId:3, PrevAnswerId:10, CurrAnswerId:10, CurrAnswerName:'Report'}
]

On window load,  I will construct the Json object using "eval()" function and do some operation in the data before its save.

On Save Click, I will call the action through the ajax call.
$.ajax({
        url: url,
        type: "GET",
        dataType: 'json',
        data: {score: ScoreJson},
     &nb

Using DataContractJsonSerializer on dynamic JSON object

  

I'm using the DataContractJsonSerializer and the DataContract and DataMember class atrributes to serialize some JSON sent to me from a 3rd party javascript component. All is working well except the component sends some dynamic data.

 

ex. { "objects": [{"object1": "value"}, {"SomeOtherObject": "anotherValue"}] ... }

 

What are my options for serializing this if the "object1", "SomeOtherObject" are all dynamic and I can add them into the class that I serialize to. Is it possible to get the JSON Serializer to convert this to a Dictionary<string, string>??

 

Also I'm using C# 3.0 so dynamics is out.



Send JSON Object to WCF

  

I have a WCF returning JSON correctly, however this WCF now needs to be extended to allow JSON Serialized objects to be posted to it. I am using JQuery to serialize objects and post it to the WCF, and when I run the project in Debug the method SimpleSearch() is being called and an object is being instantiated, however the properties are all null. Is there an error taking place in the deserialization from JSON?

Below is an extract of my WCF file, below this is the JavaScript calling the WCF using JQuery

[ServiceContract(Namespace = "http://www.link.co.uk/")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ATMService {        
       

        [OperationContract]
        [WebInvoke(RequestFormat = WebMessageFormat.Json)]
        public void SimpleSearch(SimpleObj searchRequest) {
            // Once in here the searchRequest object both Name and Postcode are null      

            }
    }

    [DataContract]
    public class SimpleObj {
        public string Name { get; set; }
        public string PostCode{ get; set; }
    }

//jQuery
function search() {   

    var searchRequest = new Object();
    searchRequest.Name = "Chris";

    var dataToSend = '{"searchRequest":[' + JSON.stringify(searchRequest) + ']}';

    $.ajax({
        type: "PO

How to return serialized JSON object from WCF

  

Hello

I am able to return the JSON string from the wcf. But i want to return the JSON object from wcf.

Is is possible to return the JSON object from the wcf? If yes , then how?

 

Thanks in advance..... 


Thinking about new C# method prototypes: object as dictionary

  
I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

C# Object Oriented Programming

  
So far in C# Essentials we have looked at the basics of programming in C# such as variable types and flow control. Although it would be possible to write a functional program using these techniques, there is much more to becoming a proficient C# programmer. C# is, above all, an object oriented programming language and as such any C# programmer will be expected to create object-oriented applications using this language.

Object Oriented Programming

  
Four core concept of OOP Object Oriented Programming. 1.Inheritance, 2.Polymorphism, 3.Abstraction and 4.Encapsulation

Object-Oriented Programming Concepts

  
This is the first in a series of articles describing the use of object-oriented programming techniques as implemented by the C# programming language. This series follows the C# Fundamentals tutorial that beginners are advised to read first.
Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend