Tag: json

从文件读取JSON?

我只是因为一个简单的看起来简单的陈述就把一些错误扔在我的脸上而感到头痛。 我有一个名为strings.json这样的json文件: "strings": [{"-name": "city", "#text": "City"}, {"-name": "phone", "#text": "Phone"}, …, {"-name": "address", "#text": "Address"}] 我现在想读取json文件。 我有我发现的这些陈述,但它不工作: import json from pprint import pprint with open('strings.json') as json_data: d = json.loads(json_data) json_data.close() pprint(d) 控制台上显示的错误是这样的: Traceback (most recent call last): File "/home/…/android/values/manipulate_json.py", line 5, in <module> d = json.loads(json_data) File "/usr/lib/python2.7/json/__init__.py", line 326, in loads return […]

你如何从Java Servlet中返回一个JSON对象

如何从Java servlet返回一个JSON对象。 以前,当用servlet做AJAX时,我返回了一个string。 有没有需要使用的JSON对象types,或者你只是返回一个看起来像一个JSON对象的string,例如 String objectToReturn = "{ key1: 'value1', key2: 'value2' }";

jQuery循环AJAX成功的JSON结果?

在jQuery的AJAX成功callback我想循环的对象的结果。 这是Firebug中响应的例子。 [ {"TEST1":45,"TEST2":23,"TEST3":"DATA1"}, {"TEST1":46,"TEST2":24,"TEST3":"DATA2"}, {"TEST1":47,"TEST2":25,"TEST3":"DATA3"} ] 我怎样才能循环的结果,以便我可以访问每个元素? 我已经尝试了下面的东西,但这似乎并没有工作。 jQuery.each(data, function(index, itemData) { // itemData.TEST1 // itemData.TEST2 // itemData.TEST3 });

将JSON反序列化成一个对象

我有一些JSON: { "foo" : [ { "bar" : "baz" }, { "bar" : "qux" } ] } 我想将其反序列化为一个集合。 我已经定义了这个类: public class Foo { public string bar { get; set; } } 但是,下面的代码不起作用: JsonConvert.DeserializeObject<List<Foo>>(jsonString); 我如何反序列化我的JSON?

使用GET从jqGrid中的列值链接到新页面

我创build了一个包含一些字段的jqGrid,比如: job_id,名字等 我想要做的是,当点击job_id列中的值时,它会将它们redirect到: job.php?job_id =(他们点击的值) 我开始尝试使用以下作为我的colModel: { name:'job_id', index:'job_id', edittype:'select', formatter:'showlink', formatoptions:{baseLinkUrl:'job.php'}, width:50, align:'center' } 但是,结果是redirect到: job.php?JOB_ID =(ROW_ID) 我做了一些search,并find了这个软件的开源版本的开发人员谁build议使用以下colModel和额外的JS: { name:'job_id', index:'job_id', edittype:'select', formatter:'showlink', formatoptions:{baseLinkUrl:'#'}, width:50, align:'center' } loadComplete: function() { var myGrid = $("#home_list"); var ids = myGrid.getDataIDs(); for (var i = 0, idCount = ids.length; i < idCount; i++) { $("#"+ids[i]+" a",myGrid[0]).click(function(e) { […]

如何将字典转换为C#中的JSONstring?

我想将我的Dictionary<int,List<int>>为JSONstring。 有谁知道如何在C#中实现这一点?

在Spring中configurationObjectMapper

我的目标是configurationobjectMapper的方式,它只是串行化的@JsonProperty注释的@JsonProperty 。 为了做到这一点,我遵循这个说明如何configurationobjectmapper。 我包含了这里描述的自定义对象映射器。 但是,当NumbersOfNewEvents类被序列化时,它仍然包含json中的所有属性。 有人有提示吗? 提前致谢 jackson1.8.0spring3.0.5 CustomObjectMapper public class CompanyObjectMapper extends ObjectMapper { public CompanyObjectMapper() { super(); setVisibilityChecker(getSerializationConfig() .getDefaultVisibilityChecker() .withCreatorVisibility(JsonAutoDetect.Visibility.NONE) .withFieldVisibility(JsonAutoDetect.Visibility.NONE) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.DEFAULT)); } } servlet.xml中 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> <context:component-scan base-package="de.Company.backend.web" /> <mvc:annotation-driven /> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> […]

由于错误的MIMEtypes,Chrome拒绝执行AJAX脚本

我试图通过AJAX访问脚本作为JSON,在Safari和其他浏览器上工作正常,但不幸的是不会在Chrome中执行。 它来与以下错误: 拒绝从'*'执行脚本,因为它的MIMEtypes('application / json')是不可执行的,并且启用了严格的MIMEtypes检查。 这是请求: $.ajax({ url: "http://some_url/test.json?callback=?", type: "GET", dataType: 'json', cache: true, success: function (data, status, error) { console.log('success', data); }, error: function (data, status, error) { console.log('error', data, status, error); } }); 有没有人有这个解决方法?

有多lessJSON可以容纳的限制?

我正在使用jQuery,JSON和AJAX评论系统。 我很好奇,有什么可以通过/存储与JSON发送的大小限制? 就像用户input了大量数据并且通过JSON发送数据,是否有某种最大限制? 也可以通过JSON发送任何types的文本。 例如有时候我允许用户使用html,这会好吗?

将postgreSQL JSON列映射到Hibernate值types

我在postgreSQL数据库(9.2)有一个jsontypes的列表。 我很难将此列映射到JPA2实体字段types。 我试图使用string,但是当我保存实体时,我得到一个exception,它不能将字符变换为JSON。 处理JSON列时使用的正确的值types是什么? @Entity public class MyEntity { private String jsonPayload; // this maps to a json column public MyEntity() { } } 一个简单的解决方法是定义一个文本列。