Posts

Showing posts with the label JSON

Donate

How To Post JSON Data With WebRequest In .NET

Hello, There was a question on how to post a JSON data using the WebRequest class on both C# and VB.NET given that using Ajax, the post data would look like this. data : '{ "age": "78", "weight": "51" }' In .NET, you need to store the JSON data into a string object and escape those double quotes before passing it to the WebRequest object. C#.NET string postData = "{ \"age\": \"78\", \"weight\": \"51\" }" ; VB.NET Dim postData As String = "{ ""age"": ""78"", ""weight"": ""51"" }" Cheers! :-)

$.getJSON() Not Loading JSON File Within Visual Studio Project In ASP.NET Web Forms

Hi, I was trying to load a JSON file located within my Visual Studio project using $.getJSON(), however the code below doesn't work as expected. $.getJSON( '/Assets/misc/employee.json' , function (data) { alert( 'processing!' ); }) .done( function (r) { alert(r.message); }) .fail( function (s) { alert( 'oops the file is missing!' ); }); After investigating for a few hours, I tested the local path of the JSON file such as http://localhost:3766/Assets/misc/employee.json and the result was an exception " HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map. ". I remember the solution in one of my ASP.NET project was to set the MimeMap in the web.config inside the system.webServer element. After setting the MimeMap for json files, I can now load local JSON files using $.getJSON(). <system.web

Unexpected character encountered while parsing value: C. Path '', line 0, position 0. (Deserialize JSON String Error In C#)

Hi, A common issue when deserializing a JSON object in C# is to pass the filepath of the JSON file to the Deserialize() method instead of the string content of that file such as the code below. var obj = JsonConvert.DeserializeObject<Employee>( @"D:\Data\Employee.json" ) When calling the Deserialize() method, you need to make sure that the parameter passed is a JSON string value instead of the file path. Use StreamReader class or File.ReadAllText() to get the content of the JSON file. using (StreamReader reader = new StreamReader( @"D:\Data\Employee.json" )) { string json = reader.ReadToEnd(); var obj = JsonConvert.DeserializeObject<Employee>(json); }

Read Or Parse Or Deserialize JSON Using JavaScriptSerializer Class In C#

Hello, Here's a simple demonstration on how to parse JSON data using .NET's JavaScriptSerializer class. Given the sample JSON data below: { "catalog": { "book": [ { "id": "bk101" , "author": "Gambardella, Matthew" , "title": "XML Developer's Guide" , "genre": "Computer" , "price": "44.95" , "publish_date": "2000-10-01" , "description": "An in-depth look at creating applications with XML." }, { "id": "bk102" , "author": "Ralls, Kim" , "title": "Midnight Rain" , "genre": "Fantasy" , "price": "5.95" , "publish_date": "2000-12-16" , "description": &q

Read JSON Array Using Json.NET JsonTextReader In C#

Image
Hello, Here's how to read or parse JSON array using Json.NET JsonTextReader class in C#.Given the sample JSON data below, you might wanna parse the information provided and retrieve the name property of a JSON Array StartObject and add it to a list box control. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 18

AnimationExtender Animation Using JSON Not Working In ASP.NET

When setting animations for AnimationExtender control using JSON/Javascript, setting the AnimationTarget with the explicit control id such as panel ID does not work when rendered to browser specified by the code below: "AnimationTarget" : "panelDescription" The workaround is to get the clientID of the panel control rendered through the browser. Below is the workaround code: //Note: this is just a fragment of the JSON animation //the actual animation might be a little bit specific than this. var animation = "AnimationTarget":"' + '<%= panelDescription.ClientID %>' + '","AnimationChildren"'; //set click behavior animationExtender.set_OnClick(animation); Cheers!

Object doesn't support property or method call in consuming JSON object From ASP.NET MVC In Internet Explorer

Recently, I've followed a simple tutorial regarding consuming JSON object in ASP.NET MVC. The error stated from the title of this post appears in IE9. The original snippet is this: $(document).ready( $.getJSON( 'http://localhost:6222/home/customerjson' , function (item) { $( '#result' ) //show product name in .html( '<p>' + item.CurrentCustomer.CustomerName + '</p>' ); } ) ); The solution is to enclose $.getJSON() in a function() statement based from the modified code below. The popup script just went away. $(document).ready( function (){ $.getJSON( 'http://localhost:6222/home/customerjson' , function (item) { $( '#result' ) //show product name in .html( '<p>' + item.CurrentCustomer.CustomerName + '</p>' ); } )

Set JSON Response In Webrequest Class

To set the JSON response of a WebRequest class, assign the ContentType property of the WebRequest object to application/json; charset=utf-8 . req.ContentType = "application/json; charset=utf-8" ; Source: Stackoverflow

Donate