http://www.verejava.com/?id=16998590966648
下载依赖 jar 包
json.jar
package com.json8;
import org.json.JSONArray;
import org.json.JSONException;
public class Test
{
public static void main(String[] args)
{
/*
题目: 将颜色数组 红色,绿色,蓝色 转成 JSON 字符串
*/
String[] colors={"红色","蓝色","绿色"};
// JSONArray 存入 colors
try
{
JSONArray jsonArray=new JSONArray(colors);
System.out.println(jsonArray.toString());
} catch (JSONException e)
{
e.printStackTrace();
}
}
}

本文介绍了一种使用Java将颜色数组转换为JSON字符串的方法。通过示例代码展示了如何利用JSONArray类将一个包含颜色名称的字符串数组转换为JSON格式。
1万+

被折叠的 条评论
为什么被折叠?



