English 中文(简体)
JSON Format for jQuery UI Autocomplete using json-simple
原标题:JSON format for jQuery UI Autocomplete using json-simple

我正试图产生一种适当的JSON输出,供公司使用。 我被迫使用JAVAjson-simple lib,我尝试了我可以想象的每一种组合。

请允许我指出,我喜欢 drop倒,以列出“Alex1”、“Alex2”、“Alex3”等。

I have tried the following

JSONObject obj =new JSONObject();
List strs = new ArrayList();
    strs.add("Alex1");
    strs.add("Alex2");
    strs.add("Alex3"); 
    strs.add("Alex4");
obj.put("source", strs);
return(obj.toJSONString());

我也曾尝试过。

JSONObject obj =new JSONObject();
Map map = new LinkedHashMap();
    map.put("id1", "Alex1");
    map.put("id2", "Alex2");
    map.put("id3", "Alex3");
    map.put("id4", "Alex4");
obj.put("source", map);
return(obj.toJSONString());

但无uck

我试图以适当的格式亲手作的尝试,我的模块非常完美地运作,因此我知道问题在于初等干事的产出。

某个人告诉我,我如何适当利用json-simple lib?

增 编

问题回答

例1

<?php
$arr = array( a  => 1,  b  => 2,  c  => 3,  d  => 4,  e  => 5);

echo json_encode($arr);
?>

The above example will output: {"a":1,"b":2,"c":3,"d":4,"e":5}

您应使用<代码>JSONArray。

JSONObject jobj = new JSONObject();
JSONArray arr = new JSONArray();

arr.add("Alex1");
arr.add("Alex2");

jobj.put("values", arr);

return jobj.toJSONString();

这将使一位具有关键意义的人物——具有一系列价值观的价值观——回到你身上。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签