Parse A Custom JSON Object In .Net?

Sep 14, 2010

For my ASP.Net application I need to use a HTTP REST API that returns a JSON object.Here's how the JSON looks:

message: [
{
type: "message"
href: "/messages/id/23"[code]....

I could use the DataContractJsonSerializer Class and have custom Classes defined. However, am not sure how keys like "$" would get converted to in .Net.

View 3 Replies


Similar Messages:

C# - How To Convert Json Object To Custom Class Object In Web Service

Aug 30, 2010

I've scenario where I want to insert data into database without post back. there are around 12 to 13 fields which i need to insert. I'm passing DTO from the client side which is actually Json object. Now the problem which i'm facing is how to convert that Json object which i got in webservice to the "class" (in my case class name is User) object.

[Code]....

In the above case AddNewUser method takes the object of User class. But i'm getting casting error. So how do I convert Json object to the "User" class object?

View 3 Replies

How To Convert JSON Object To Custom C# Object

Feb 11, 2010

Is there an easy way to populate my C# Object with the JSON object passed via AJAX?

//This is the JSON Object passed to C# WEBMETHOD from the page using JSON.stringify
{"user":{"name":"asdf","teamname":"b","email":"c","players":["1","2"]}}
//C# WebMetod That receives the JSON Object
[WebMethod]
public static void SaveTeam(Object user)
{
}
//C# Class that represents the object structure of JSON Object passed in to the WebMethod
public class User
{
public string name { get; set; }
public string teamname { get; set; }
public string email { get; set; }
public Array players { get; set; }
}

View 4 Replies

Jquery - Json.net Web Service - How To Return And Parse Dates

Aug 10, 2010

After much head scratching as to why my returned Json string is breaking JSON.parse, I have realized that it is the returned dates that it doesn't like.

.net property:-

[code]....

View 2 Replies

How To Convert JSON String To JSON Object Using JavaScript

Jan 21, 2011

I use the JavaScriptSerializer class of ASP.net to serialize my object and return it to the client side. How can I deserialize the string using JavaScript?

View 4 Replies

Data Controls :: Parse JSON Data From URL And Display In GridView

May 7, 2015

How to parse [URL].....

I am referring below link of urs : How to read JSON string into DataTable and Class object using C# .Net 

my code to get data into string :

        Dim data As String = New System.Net.WebClient().DownloadString("[URL]") 

now i want it to get into data table , so that i can bind it with grid later on.

 JSON String

{"
record":
[{"id":"0",
"Date":"11/14/2014",
"Time":"12:00AM",
"programme":"Stops Here",
"synopsis":"A show that brings you the big interviews",

[Code]......

View 1 Replies

MVC :: How To Pass JSON Object As Dictionary Object

Oct 23, 2010

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 dictionary object

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

View 5 Replies

C# - Give A Custom Control Ability To Parse XML Markup To A Collection?

Apr 1, 2010

I'm writing a custom ASP.NET webcontrol and would like it to have a collection of custom items which can also be specified in the XML markup. Something like this:

class MyControl: WebControl
{
public IList<MyItemType> MyItems { get; private set; }
}

And in the markup:

<asd:MyControl runat="server" id="mc1">
<MyItems>
<MyDerivedCustomItem asd="dsa"/>
<MyOtherDerivedCustomItem asd="dsa"/>
</MyItems>
</asd:MyControl>

How do I do this? I though this was all about implementing some interface on the collection or adding some special attributes to the property, but nothing I do seems to work.

View 2 Replies

MVC :: How To Get Datetime From Json Object

Oct 21, 2010

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...

View 1 Replies

Could Not Deserialize JSON Object

Feb 23, 2010

We are trying to consume WCF service which returns employee details in JSON Format.

like:

{"d":[{"_type":"Employee:#","BigThumbNailURI":null,"ID":1,"Name":"E1"},{"_type":"Employee:#","BigThumbNailURI":null,"ID":2,"Name":"E1"}]}

From VB.net code behind when I am trying to deserialize it it's stating that

"Expecting state 'Element'.. Encountered 'Text' with name '', namespace ''."

Deserialization code snippet:

Dim serializer = New DataContractJsonSerializer(GetType(List(Of Employee)))
Dim memoryStream = New MemoryStream()
Dim s = msg.Content.ReadAsString()
serializer.WriteObject(memoryStream, s)
memoryStream.Position = 0.......

View 2 Replies

How To Convert JSON String To Object In C#

Oct 7, 2010

If I have a string containing valid JSON

how can I convert to an obect in c#?

View 2 Replies

WCF / ASMX :: Can Get Different Json Datasets From The Same Object

Apr 6, 2010

I want to serialize an object to json, so I'm using [Code]....

[Code]....

This is fine, but I want to return different json datasets depending on the circumstances. Lets say I have this object (a simplified example):

[DataContract]
class foo
{
[DataMember] int productId
[DataMember] string productName
double price; //not used in json.. yet
}

Which will serialize to a json object containing the product name & Id, but what if I also need to be able to return a different json object (say, productId and price but not name)? Can this be done somehow in the same object using WCF/DataContracts and DataMembers? This will be sent in an ajax query containing a collection of objects and needs to fast, so just including every member in every type of json request whether it's needed or not isn't a good solution.

View 1 Replies

Serializing Only Parts Of An Object With Json?

Feb 14, 2011

I have an object called MyObject that has several properties. MyList is a list of MyObject that I populate with a linq query and then I serialize MyList into json. I end up with something like this

List<MyObject> MyList = new List<MyObject>();

MyList = TheLinqQuery(TheParam);

var TheJson = new System.Web.Script.Serialization.JavaScriptSerializer();

string MyJson = TheJson.Serialize(MyList);

What I want to do is serialize only parts of MyObject. For instance, I might have Property1, Property2...Propertyn and I want MyJson to only include Property3, Property5 and Property8.
I thought of a way to do this by creating a new object with only the properties I want and from there create a new list for the serialization.

View 1 Replies

C# - Error Converting JSON To .Net Object?

Apr 19, 2010

I am unable to convert JSON string to .net object in asp.net. I am sending JSON string from client to server using hidden field (by keeping the JSON object.Tostring() in hidden field and reading the hidden field value in code behind file)

Json string/ Object:

[[{"OfferId":"1","OrderValue":"11","HostingTypeID":"3"},
{"OfferId":"1","OrderValue":"11","HostingTypeID":"3"},
{"OfferId":"1","OrderValue":"11","HostingTypeID":"3"},
{"OfferId":"1","OrderValue":"2","HostingTypeID":"3"},

[Code]....


While converting i am getting following error:

Expecting element 'root' from namespace ''.. Encountered 'None' with name '', namespace ''.

View 3 Replies

C# - Declare And Use The Name Of A Function From A Json Object?

Apr 20, 2010

I have a json object collection of geo locations that I build in the server. Each of those objects has two properties: "marker" and "onClick". Marker is for storing a Google Maps marker object and the onClick stores the name of the function to be called when that marker is clicked on the map.When I'm pushing the location objects into an array using javascript in the client side, I create the markers and assign them to each location object within the array.

My problem is that when I bind the marker with the onClick property, the function won't be found in the DOM and get an error.Is there a way to declare a property in a json object for using it on an event binding?

View 1 Replies

MVC :: Extract Values From $.to JSON Object?

Mar 25, 2011

I have the following result in my controller from the $.toJSON method;

"[{"param":"Update Payment","value":"50.00"}]"

How do I extract the values from param: and value: ???

View 4 Replies

C# - Web Service Method Returns Response Object Instead Of Custom Object?

Sep 29, 2010

I have the following code:

[WebMethod]
[SoapHeader("_webServiceAuth")]
public User GetUser(string username){
try
{
this._validationMethods.Validate(_webServiceAuth);
User user = new User(username);
[code]...

View 1 Replies

Javascript - How To Make Json Child Nodes (JSON Inside JSON)

Aug 11, 2010

I try to use the jquery + json to get all elements in form and build a JSON var to post in a ASP.NET MVC method.

[Code]....

It method get all fields in a form and build a JSON, but it dont put JSON inside JSON.

Example:

If i have the follow form:

<input name="person.name"><input name="person.age"><input name="person.address.street">

The serialized string build a JSON like this

{ "person.name": "??", "person.age": "??", "person.address.street": "??" }

I need a plugin or some function to generate like this:

{ "person": { "name" : "??", "age" : "??", "address":{ "street": "??" } } }

View 1 Replies

AJAX :: Getting JSON Object With Structure But No Content?

Jun 16, 2010

My json response contains json with structure (eg. "[[[],[]]]") but no actual content.

AJAX code:

[Code]....

It definitely recognizes structure (if I change the xml nodes, it reflects in the []'s) but just isn't inserting any content. I tried prefixing the web method with "<ScriptMethod(ResponseFormat:=ResponseFormat.Json)>" but it made no difference.

View 5 Replies

Jquery - How To Convert An Object List Into JSON

Mar 20, 2010

I have a list of person objects which I want to send in response to a jquery' ajax request. I want to send the list into JSON format. The list is as follows -

List<Person> PersonList = new List<Person>();
Person Atiq = new Person("Atiq Hasan Mollah", 23, "Whassap Homie");
Person Sajib = new Person("Sajib Mamud", 24, "Chol kheye ashi");
PersonList.Add(Atiq);
PersonList.Add(Sajib);

How can I convert the "PersonList" list into JSON ?

View 1 Replies

JQuery :: Get Field Value From Json Object Using An Index?

Feb 17, 2011

I would like to get a field value using an index on an json object.

The json object looks like : {PartList:[{Field1:"echo",Field2:"bravo"},{Field1:"yes",Field2:"no"}]}

I know that if I would like to have the Field1 value it is on the index 0, and for example for the first item in the array:

jsonObject.PartList[0][0] , here the first index is working but the second index given is not. But is it possible to do this ?

View 4 Replies

MVC :: JSON Object - Grid Is Not Filling Properly

Feb 25, 2011

I've created a simple (or what I thought was simple!) search form using Razor, MVC3 and the webgrid from the web helpers. I enabled paging, used a great article I found here to get that working... or so I thought. Basically what happens is that when I click the page buttons at the bottom of the grid it does something that I didn't expect, and creates a JSON object, then the browser prompts me to try and save it, and not as I expected to refill the grid. I can't see what I'm doing wrong, and before I break my monitor by throwing it onto the railway line!

[Code]....

My jQuery code

[Code]....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;
using System.Configuration;
using System.Web.Helpers;
namespace MvcApplication1.Controllers
{
public class SearchController : Controller
{
//
// GET: /Search/
Entities t = new Entities(ConfigurationManager.ConnectionStrings["Entities"].ConnectionString);
public ActionResult Details(int id)
{
Tender_Question q = (from x in t.Tender_Questions where x.Unique_ID_number == id select x).SingleOrDefault();
Customer c = (from cu in t.Customers where cu.CustomersID == q.Company select cu).SingleOrDefault();
ViewBag.Customers = c.CompanyName;
Panel_type pan = (from pa in t.Panel_types where pa.ID == q.Panel_type select pa).SingleOrDefault();
ViewBag.Panel = pan.Panel_type1;
return View(q);
}
[HttpGet]
public ActionResult Edit(int id)
{
Tender_Question q = (from x in t.Tender_Questions where x.Unique_ID_number == id select x).SingleOrDefault();
List<Customer> c = (from cu in t.Customers select cu).ToList();
ViewBag.Customers = c;
return View(q);
}
[HttpPost]
public ActionResult Edit(Tender_Question model)
{
if (ModelState.IsValid)
{
Tender_Question q = (from x in t.Tender_Questions where x.Unique_ID_number == model.Unique_ID_number select x).SingleOrDefault();
q.Answer = model.Answer;
q.Company = model.Company;
q.Customer = model.Customer;
q.Date = model.Date;
q.Page_Question_Ref = model.Page_Question_Ref;
q.Panel_type = model.Panel_type;
q.Question = model.Question;
q.Type_of_tender = model.Type_of_tender;
//add update code
t.SaveChanges();
return RedirectToAction("Index");
}
else
{
return View(model);
}
}
[HttpGet]
public ActionResult Search(int? page)
{
if (page.HasValue)
{
return RedirectToAction("EfficientPaging", new { page = page });
}
else
{
return View();
}
}
[HttpPost]
public ActionResult Search(int? page, FormCollection collection)
{
TempData.Clear();
IEnumerable<Tender_Question> q = getSearch(collection);
TempData.Add("Results", q);
return View(q);
}
private IEnumerable<Tender_Question> getSearch(FormCollection collection)
{
string question;
string answer;
IEnumerable<Tender_Question> q = t.Tender_Questions;
question = collection["Question"];
answer = collection["Answer"];
if (!string.IsNullOrEmpty(question))
{
if (question.EndsWith(","))
{
question = question.Substring(0, question.Length - 1);
} if (question.Length > 0)
{
if (question.Contains(","))
{
string[] questioned = question.Split(',');
foreach (string s in questioned)
{
q = q.Where(m => m.Question.Contains(s));
}
}
else
{
q = q.Where(m => m.Question.Contains(question));
}
}
}
if (!string.IsNullOrEmpty(answer))
{
if (answer.EndsWith(","))
{
answer = answer.Substring(0, answer.Length - 1);
}
if (answer.Length > 0)
{
if (answer.Contains(","))
{
string[] answered = answer.Split(',');
foreach (string s in answered)
{
q = q.Where(m => m.Answer.Contains(s));
}
}
else
{
q = q.Where(m => m.Answer.Contains(answer));
}
}
}
return q;
}
[HttpGet]
public ActionResult EfficientPaging(int? page)
{
IEnumerable<Tender_Question> q = (IEnumerable<Tender_Question>)TempData["Results"];
int skip = page.HasValue ? page.Value - 1 : 0;
q = q.OrderBy(o => o.Unique_ID_number).Skip(skip * 10).Take(10).ToList();
var grid = new WebGrid(q);
var column = new WebGridColumn();
column.CanSort = false;
column.ColumnName = "Unique_ID_number";
column.Header = "Edit";
column.Format = (item) =>
{
return new HtmlString("<a href="/Home/Edit/" + column.ColumnName + "">Edit</a> ");
};
var detcolumn = new WebGridColumn();
detcolumn.CanSort = false;
detcolumn.ColumnName = "Unique_ID_number";
detcolumn.Header = "Details";
detcolumn.Format = (item) =>
{
return new HtmlString("<a href="/Home/Details/" + column.ColumnName + "">Details</a> ");
};
var htmlString = grid.GetHtml(htmlAttributes: new { id = "DataTable" }, columns: grid.Columns(
column, detcolumn,
grid.Column("Question"),
grid.Column("Answer"),
grid.Column("Company"),
grid.Column(columnName: "Type_of_tender", header: "Type of Tender"),
grid.Column(columnName: "Panel_type", header: "Panel type"),
grid.Column(columnName: "Page_Question_Ref", header: "Page Question Ref"),
grid.Column("Date")
));
return Json(new
{
Data = htmlString.ToHtmlString(),
Count =q.Count() / 10
}, JsonRequestBehavior.AllowGet);
}
}
}

View 4 Replies

Deserialize Unnamed Json Array Into An Object In C#?

Jun 3, 2010

Wondering how to deserialize the following string in c#:

"[{"access_token":"thisistheaccesstoken"}]"

I know how to do it if the json was:

"{array=[{"access_token":"thisistheaccesstoken"}]}"

I'd do it like this:

public class AccessToken
{
public string access_token {get;set;}
public DateTime expires { get; set; }
}
public class TokenReturn
{
public List<AccessToken> tokens { get; set; }
}
JavaScriptSerializer ser = new JavaScriptSerializer();
TokenReturn result = ser.Deserialize<TokenReturn>(responseFromServer);

View 1 Replies

JQuery :: Creating JSON Object From AD Query

Mar 23, 2011

I'm new to Jquery, JSON and MVC, and am trying to create a json object that contains AD info from an AD query. The ad query is working fine and returning data and I have 2 overloaded implementations of it.

#1 is a method from an older .net app that builds and returns a datatable that we bound to a grid view control

#2 was a modification of #1 that returns a System.Collections.Generic.List<> type. #2 returns data ok and i can display a table in the MVC view

however, I'd like to get the data results into a json object so i can bind it to a jqGrid object that has similar functionality to the old .Net server controls (Delete, Update, Sort) Here's the new method that's part of a C# static class:

[Code]....

Like I said...I'm new to this way of doing web development, so I'm not sure how to even approach getting this data into a json object.

View 2 Replies

MVC :: Display JSON Object In JQuery Grid?

Jun 3, 2010

I am working on ASP MVC 2 application. I have used the following jquery plugin & css

<link href="../../Content/ui.jqgrid.css" rel="stylesheet" type="text/css" />

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved