【php数组转换json有问题大家过来看看】教程文章相关的互联网学习教程文章

PHP / json_encode:处理混合数组和具有数字属性的对象【代码】

我最近不得不解决遗留PHP应用程序中的错误.此应用程序从另一个应用程序接收具有以下形式的JSON的请求:{"someList": ["item A","item B"],"ratings": {"0": 0.001234,"1": 0.0666,"2": 0.09876,"3": 0.777777} }当将其反序列化为本机PHP“关联数组”时,列表和映射(使用键0,1,2和3)看起来都像列表.那没关系,我可以解决这个问题.但是,此应用程序会对此数据进行计算,并在以大致相同的格式序列化回JSON并将其发送到另一个应用程序之前添...

java – 数组上的JAXB JSON强制括号【代码】

我试图在仅包含一个元素的列表上强制使用括号. 我想要这样的东西:{“id”:“0”,“industries”:[{“id”:“0”,“name”:“Technologies”}],“name”:“Google Inc.”} 但我得到:{“id”:“0”,“industries”:{“id”:“0”,“name”:“Technologies”},“name”:“Google Inc.”} 这是我的实体:@Entity @XmlRootElement public class Company {private int id;private String name;private String description;@X...

java获取json数组格式中的值【代码】

第一种方法: String str = "{array:[{id:5,name:张三},{id:6,name:李四}]}";JSONArray jsonArray = null;jsonArray = jsonobj.getJSONArray("array");//获取数组System.out.println(jsonArray.getJSONObject(0).get("name"));String str = "[{columnId:5,columnName:人文历史},{columnId:2,columnName:商业视野}]}"; JSONArray jsonArray = null; jsonArray = new JSONArray(str); System.out.println(jsonArray.getJSONObject(0)...

使用jQuery将Javascript数组发送到PHP脚本时哪个更好:使用JSON还是让jQuery将其转换为查询字符串?【代码】

我正在使用jQuery的$.ajax函数和POST方法将javascript数组发送到PHP脚本(AFAIK,GET方法将是模拟的):fruits = [{color: "yellow",taste: "sour"},{color: "blue",taste: "semi-sweet"}, ]$.ajax({url: "php/script.php",data: {fruits: fruits},type: "POST", });发出请求后,PHP中的$_POST变量填充为:$_POST['fruits'][0]['color'] $_POST['fruits'][0]['taste'] $_POST['fruits'][1]['color'] $_POST['fruits'][1]['taste']或者,...

将JSON数组转换为Java类对象列表【代码】

我有一个来自WFC服务的JSON字符串.当我尝试将JSON数组转换为List对象时,我遇到以下错误:".JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: java.io.StringReader@41f27f18; line: 1, column: 1]"Java类(卡类):public class Card {public String ID;public String CompanyID;public String CompanyName;public String FiscalCode;public String Limit;public ...

如何将数组从php(使用json_encode)传递给javascript【代码】

我的java脚本.我想要显示图像. javascript需要图像路径作为数组格式.我试图提供路径抛出ajax.它不起作用.当我使用硬编码工作.我的javascipt如下.它不起作用. javascript下面的工作代码供应和我的php文件代码也在那里.$(function () {$.get( "php/building_edit_image_get_db.php", function( your_return_data ) {alert(your_return_data);$("#editimagefile").fileinput({showUpload: false,showCaption: false,overwriteInitial:...

java – 筛选包含数组部分的JSON文件【代码】

我有一个函数,允许我使用另一个JSON对象作为过滤器过滤掉某些JSON文件. 看代码:public Map<String, Entry<JsonObject, Long>> loadFilter(Coll<?> coll, JsonObject filter){// Create RetMap<String, Entry<JsonObject, Long>> ret = null;// Get DirectoryFile directory = getDirectory(coll);if ( ! directory.isDirectory()) return ret;// Find AllFile[] files = directory.listFiles(JsonFileFilter.get());// Create Ret...

javascript – 如何将枚举数组序列化为Json字符串数组?【代码】

参见英文答案 > Serialize a container of enums as strings using JSON.net 2个基于迭戈在这个问题中最高投票回答的未答复评论: JSON serialization of enum as string 所以对于一个枚举:public enum ContactType {Phone = 0,Email = 1,Mobile = 2 }而对于例如.财产://could contain ContactType.Phone, ContactType.Email, ContactType.Mobile IEnumerable<ContactType> AvailableContact...

PHP json_decode()输出:对象与数组?【代码】

对于函数json_decode(),有2个输出选项,JSON Object或Array.$obj = json_decode($json_string, false);要么$array = json_decode($json_string, true);哪种类型表现更好?解决方法:对于函数json_decode(),人们可能会在将结果输出为Object或Associate Array之间挣扎.在这里我进行了基准测试. 使用的代码(其中$json_string是Google Maps V3地理编码API的JSON输出):// object $start_time = microtime(true); $json = json_decode($js...

javascript – 在ExpressJS中使用带有数组的JSON【代码】

在网页上我使用jQuery发布了一些JSON:$.post('/url', data);我的数据是一个javascript对象,包含一些值和一个数组. JSON.stringify(data)看起来像:{"favoriteAnimal":"piglet", "okayAnimals":["cats","dogs"]} 我正在使用ExpressJS(与身体解析器中间件连接)在NodeJS webapp中使用这个JSON.我可以检索像req.body.favoriteAnimal这样的最喜欢的动物,它给了我一个很好和花花公子的字符串仔猪. 但是如何访问数组中的值?req.body.fav...

java – 在Spring MVC控制器中反序列化json数组【代码】

我发送一个json对象列表,并尝试在我的Spring控制器中反序列化它.但是我一直得到“错误请求”的错误并导致状态代码为415.但是,我的json数组是有效的. json是 – {“users”: [{“userName”: “john”,“email”: “john@gmail.com”,“user_id”: “u223344”},{“userName”: “Smith”,“email”: “smith@gmail.com”,“user_id”: “u223345”}]}Ajax调用如下 – $.ajax({ url: $("#addNewUser").attr("action"), data: JSON.s...

c# – Newtonsoft.JSON:JSON列表和数组的处理方式不同【代码】

参见英文答案 > Explanation for ObjectCreationHandling using Newtonsoft JSON? 2个给出以下代码:public class ColorList {public List<string> Colors = new List<string>(new string[1] { "#eeeeee"}); } public class ColorArray {public string[] Colors = new string[1] { "#eeeeee"}; }public class Program {public static void Main(){string json = "{Colors:['#abc','#123']}";...

javascript – 在JSON数组中添加新对象【代码】

我正在使用javascript和JSON.我有一个像这样的JSON对象:{"firstName":"John", "lastName":"Doe", "id":"1"}就我而言,我有一个像这样的功能:function addNewValues(jsonArray, firstName, lastName, id)如果“firstName”不匹配,我应该在数组中创建一个新值. 从addNewValues({"firstName":"John", "lastName":"Doe", "id":"1"}, "Jane", "Doe", "2"); 它应该返回:[ {"firstName":"John", "lastName":"Doe", "id":"1"}, {"firstN...

如何在PHP中将此字符串解析为json或数组格式?【代码】

这是Google Adwords API的回复Details: [fieldPath: id; trigger: Invalid predicate name: id; errorString: SelectorError.INVALID_PREDICATE_FIELD_NAME]我想将它解析为json / array,如下所示:"Details": {"fieldPath": "id", "trigger": "Invalid predicate", "name": "id", "errorString": "SelectorError.INVALID_PREDICATE_FIELD_NAME" }解决方法:您可以使用str_replace将字符串转换为可解析的格式.然后将parse_str转换为数...

HashMap到Json数组对象 – Java【代码】

我有一个HashMap,我需要解析为JSON:HashMap<String, Integer> worders = new HashMap<>();我需要将它解析为JSON对象数组.当前值:{"and": 100}, {"the": 50}需要的JSON格式:[ {"word": "and", "count": 100}, {"word": "the", "count": 50} ]我已经意识到我需要使用循环将其置于正确的格式,但不知道在哪里或如何开始. 我也使用ObjectMapper()将其写为JSON,但是,这不能纠正格式,谢谢你的帮助.解决方法:实际上,您不需要创建正式的J...