天道酬勤,学无止境

json

Access-Control-Allow-Origin with Wikipedia API with Javascript

Trying to receive a response from the Wikipedia API on Codepen. The reply should be a json which i'm trying to console.log. In the console however I see an error: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://en.wikipedia.org/w/api.php?action=opensearch&search=earth&format=json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). I've read quite a bit over the past few days about CORS and Allow-Origin to try to understand but for some reason even when I think I understand... I cannot manage to implement :) However, the most

2022-01-19 02:34:47    分类:问答    javascript   json   cors   wikipedia-api

Nancy maximum JSON length exception when Binding

I have simple Nancy self hosting C# project which deserializes data in NancyModule like this: Post["/build"] = (something) => { var data = this.Bind<Brick>(); } I am getting "Maximum JSON input length has been exceeded." when Request.Body.Length is close to 2MB. I would like to send tens of megabytes of data in the future and 2MB is just too low. Can I remove this limit?

2022-01-19 02:32:15    分类:问答    c#   json   nancy

Convert AJAX date to Javascript date for use with ng-model

I am using $http.get in a service in to fetch JSON data. One of my object properties in the returned JSON is a date which is not being parsed by AngularJS. I need to bind this property to a date field and I am currently working around it by manually converting the JSON string to a javascript date after fetching the AJAX data as shown below app.service('MainService', function(){ var self = this; self.jsonDate = null; self.parsedDate = null; // this function will get JSON data from an API in production self.getData = function(){ var jsonData = "2014-06-13T16:00:00"; // Angular does not convert

2022-01-19 02:23:27    分类:问答    json   angularjs   momentjs

Rails 3.2, handle corrupted request bodies (MultiJson::DecodeError)

I'm working on a Rails 3.2.11 application (MRI 1.9.3). PArt of it is a webservice that receives POST requests with JSON serialized bodies. Everything works, but I want it to be resilient to bad formatted requests, e.g. invalid JSON. Right now, if it receives a JSON with – let's say – a missing comma, it will return a 500 error with an HTML response containing the default rails error view (plus the backtrace when in dev). I want to customize it to return a JSON or XML response with info about the error. The error is MultiJson::DecodeError and I know I can trap exceptions with rescue_from in the

2022-01-19 02:17:44    分类:问答    ruby-on-rails   ruby   json   rack

JSON.stringify does not work in IE

I have used the following method: JSON.stringify(json,null,2); This produces tabbed output in all browsers except IE: in IE, it displays a single line. Is null the problem and if so what are the alternatives?

2022-01-19 02:11:51    分类:问答    json   internet-explorer

how to pass javascript variable value to views.py function in django?

I am trying to send a string generated from javascript tag in my html page to views.py function. I'll use that value to render it to another html page where another javascript will use it. This is the variable which parses json data: var url = data.result.docs[i].source.enriched.url.url; I want to send "url" to my function in views.py but i am not able to figure out a way. Also i want to keep a link, so that when user click it the "url" is passed to views.py and my function there send it to other html file. sjd += "<br/>" + data.result.docs[i].source.enriched.url.title + '<a href="/rawHtmlText

2022-01-19 01:50:58    分类:问答    javascript   json   django

Deserialize duplicate keys to list using Jackson

I'm trying to deserialize json into object. However, the json has duplicate keys. I cannot change the json and I would like to use Jackson to change duplicate keys to a list. Here is an example of the json I retrieve: { "myObject": { "foo": "bar1", "foo": "bar2" } } And here is what I would like after deserialization: { "myObject": { "foo": ["bar1","bar2"] } } I created my class like so: public class MyObject { private List<String> foo; // constructor, getter and setter } I tried to use DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY from objectMapper but all it does is taking the last key

2022-01-19 01:06:59    分类:问答    java   json   spring-boot   jackson

Delphi - Unit x was compiled with a different version of x, when fixing a VCL bug

I am using Delphi XE6 and using Datasnap and JSON in my project. There is a bug I want to correct in the VCL unit System.JSON.pas (in the TJSONString.ToString function) where it should be escaping backslash characters as well as quotes. In order to fix this I carried out the following : Copied System.JSON.pas from the standard VCL source folder to my project source folder Added System.JSON.pas to my project (using the newly copied file) Fixed the bug and attempted to compile I get the error 'Unit Data.DBXCommon was compiled with a different version of System.JSON.TJSONObject' I can see that

2022-01-19 01:01:27    分类:问答    json   delphi   vcl   datasnap

Format and append JSON data to html div [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago. Improve this question I am using JSON data in my application and here is a sample code of my json data. { "myMenu":[ { "id":"1", "name":"name 01", "image":"img_url", "other":[ { "image":"img_url", "name":"name_01" }, { "image":"img_url", "name":"name_02" }, { "image":"img_url", "name":"name_03" }, { "image":"img_url", "name":"name_04" }, { "image":"img_url", "name":"name_05" } ] }, {

2022-01-19 00:44:03    分类:问答    javascript   jquery   html   json

can't serialize class in MongoDB Java and String are encoded

My simple application is suppose to just populate MongoDB with a mapping between _id to user. My key (_id) is in JSON format and its value is just a long. { "_id": { "a": "1B2ac", "b": "Windows NT 5.2; WOW64; rv:16.0 Ff/6.0" }, "user": 1999129 } I have a couple of issues: Issue 1: I get can's serialize class... when I try to insert: Caused by: java.lang.IllegalArgumentException: can't serialize class test.mongo.foo.DummyObject at org.bson.BSONEncoder._putObjectField(BSONEncoder.java:234) at org.bson.BSONEncoder.putObject(BSONEncoder.java:121) at org.bson.BSONEncoder.putObject(BSONEncoder.java

2022-01-19 00:32:42    分类:问答    java   json   mongodb