本文实例陈述了php array 转json及java 调换json数据格式操作。共享给我们供我们参考,具体如下:
php array 转json 数据
$arr = array( "demo1" => "my demo1", "demo2" => array( "demo2_demo1"=>"aaaaaaaa", "demo2_demo2"=>"bbbbbbbb", "demo2_demo3"=>array( "demo2_demo3_demo1"=>"ccccccc" ) ), "demo3" => 22);$json_str = json_encode;$arr = json_decode;var_dump;var_dump;//查看结果
string "{"demo1":"my demo1","demo2":{"demo2_demo1":"aaaaaaaa","demo2_demo2":"bbbbbbbb","demo2_demo3":{"demo2_demo3_demo1":"ccccccc"}},"demo3":22}"array { ["demo1"]=> string "my demo1" ["demo2"]=> array { ["demo2_demo1"]=> string "aaaaaaaa" ["demo2_demo2"]=> string "bbbbbbbb" ["demo2_demo3"]=> array { ["demo2_demo3_demo1"]=> string "ccccccc" } } ["demo3"]=> int}
java json数据格式调换重视包
commons-beanutils-1.8.3.jar,commons-collections-3.2.1.jar,commons-lang-2.6.jar,commons-logging-1.1.1.jar,ezmorph-1.0.6.jar,json-lib-2.4-jdk15.jar,
package Main;import net.sf.json.JSONObject;import net.sf.json.JSONArray;import java.util.Map;import java.util.HashMap;import java.util.List;import java.util.ArrayList;import Main.Demo1;public class Index { public static void main { index4(); } /** * 简单的simple * */ public static void index1() { JSONObject json = new JSONObject(); json.element; json.element; System.out.println; } /** * Map 数据转json * */ public static void index2() { JSONObject json = new JSONObject(); Map map = new HashMap(); map.put; map.put; json.accumulateAll; System.out.println; } /** * List 转json * */ public static void index3() { JSONArray arr = new JSONArray(); List> list = new ArrayList>(); list.add; list.add; arr.addAll; System.out.println; } /** * 对象转Json * */ public static void index4() { Demo1 demo1 = new Demo1(); demo1.setName; demo1.setAge; JSONObject json = new JSONObject(); JSONArray arr = new JSONArray(); json.element; arr.add; //json.containsKey; System.out.println; System.out.println; } private static Map getMap(String key,String val) { Map map = new HashMap; return map; }}
package Main;public class Demo1 { private String name; private int age; public void setName { this.name = name; } public String getName() { return this.name; } public void setAge { this.age = age; } public int getAge() { return this.age; }}
越多关于 JSONObject 提供的秘诀 JSONArray 提供的秘籍 本人搜求。
PS:这里再为我们推荐两款相比实用的json在线工具供大家参谋运用:
在线JSON代码核算、核算、美化、格式化学工业具:
JSON在线格式化学工业具:
在线XML/JSON相互调换工具:
json代码在线格式化/美化/压缩/编辑/转变工具:
C语言风格/HTML/CSS/json代码格式化美化学工业具:
越来越多关于PHP相关内容感兴趣的读者可查阅本站专项论题:《PHP中json格式数据操作技艺汇总》、《PHP数学生运动算技巧总计》、《PHP基本语法入门教程》、《PHP数组操作技巧大全》、《php字符串用法计算》、《php+mysql数据库操作入门教程》及《php不感到奇数据库操作手艺汇总》
希望本文所述对我们PHP程序设计具备利于。
本文由威尼斯888发布于计算机网络 / 编程,转载请注明出处:本文实例讲述了php array 转json及java 转换
关键词: