for row in cursor.fetchall():
count_rows+=1
result_inside={}
row_content=[]
for col, val in zip(col_names, row):
# проверяем наличие атрибута у объекта, если CLOB то приеняем read
if hasattr(val, 'read'):
result_inside[col] = val.read()
else:
result_inside[col] = val
row_content.append(result_inside[col])
json_file.write(json.dumps(result_inside, default = myconverter))
for row in cursor:
count_rows+=1
result_inside={}
row_content=[]
for col, val in zip(col_names, row):
# проверяем наличие атрибута у объекта, если CLOB то приеняем read
if hasattr(val, 'read'):
result_inside[col] = val.read()
else:
result_inside[col] = val
row_content.append(result_inside[col])
json_file.write(json.dumps(result_inside, default = myconverter))
public class Employee3 {
private String Employee;
private String Input_Weight1;
private String Input_Weight2;
private String Input_Weight3;
public String getEmployee() {
return Employee;
}
public void setEmployee(String employee) {
Employee = employee;
}
public String getInput_Weight1() {
return Input_Weight1;
}
public void setInput_Weight1(String input_Weight1) {
Input_Weight1 = input_Weight1;
}
public String getInput_Weight2() {
return Input_Weight2;
}
public void setInput_Weight2(String input_Weight2) {
Input_Weight2 = input_Weight2;
}
public String getInput_Weight3() {
return Input_Weight3;
}
public void setInput_Weight3(String input_Weight3) {
Input_Weight3 = input_Weight3;
}
}
List<String> Employee = new ArrayList<>();
List<String> Input_Weight1 = new ArrayList<>();
List<String> Input_Weight2 = new ArrayList<>();
List<String> Input_Weight3 = new ArrayList<>();
Employee.add("сотрудник1");
Employee.add("сотрудник2");
Employee.add("сотрудник3");
Input_Weight1.add("0.2");
Input_Weight1.add("0");
Input_Weight1.add("0");
Input_Weight2.add("0.4");
Input_Weight2.add("0");
Input_Weight2.add("0");
Input_Weight3.add("0.3");
Input_Weight3.add("0");
Input_Weight3.add("0");
Employee3 employee3=null;
JSONArray jsonobj = new JSONArray();
// List<Employee3> map_list=new ArrayList<>();
for (int i=0; i<Employee.size(); i++){
employee3=new Employee3();
employee3.setEmployee(Employee.get(i));
employee3.setInput_Weight1(Input_Weight1.get(i));
employee3.setInput_Weight2(Input_Weight2.get(i));
employee3.setInput_Weight3(Input_Weight3.get(i));
// map_list.add(employee3);
// System.out.println(Employee.get(i));
jsonobj.put(employee3);
}
Gson gson1 = new Gson();
System.out.println(gson1.toJson(jsonobj));
List<String> Employee = new ArrayList<>();
List<String> Input_Weight1 = new ArrayList<>();
List<String> Input_Weight2 = new ArrayList<>();
List<String> Input_Weight3 = new ArrayList<>();
Employee.add("сотрудник1");
Employee.add("сотрудник2");
Employee.add("сотрудник3");
Input_Weight1.add("0.2");
Input_Weight1.add("0");
Input_Weight1.add("0");
Input_Weight2.add("0.4");
Input_Weight2.add("0");
Input_Weight2.add("0");
Input_Weight3.add("0.3");
Input_Weight3.add("0");
Input_Weight3.add("0");
Employee3 employee3=null;
JSONArray jsonobj = new JSONArray();
// List<Employee3> map_list=new ArrayList<>();
for (int i=0; i<Employee.size(); i++){
employee3=new Employee3();
employee3.setEmployee(Employee.get(i));
employee3.setInput_Weight1(Input_Weight1.get(i));
employee3.setInput_Weight2(Input_Weight2.get(i));
employee3.setInput_Weight3(Input_Weight3.get(i));
// map_list.add(employee3);
// System.out.println(Employee.get(i));
jsonobj.put(employee3);
}
Gson gson1 = new Gson();
System.out.println(gson1.toJson(jsonobj));
[{"Employee":"сотрудник1","Input_Weight1":"0.2","Input_Weight2":"0.4","Input_Weight3":"0.3"},{"Employee":"сотрудник2","Input_Weight1":"0","Input_Weight2":"0","Input_Weight3":"0"},{"Employee":"сотрудник3","Input_Weight1":"0","Input_Weight2":"0","Input_Weight3":"0"}]
// конвертируем JSON Object в массив
function JSONtoArray(JSONObject) {
var result = [];
for(var k in JSONObject) {
var v = JSONObject[k];
result.push(k, v);
}
return result;
}
$.getJSON( "employees?region="+encodeURI(selected), { selected_region: selected } )
.done(function( jsondata ) {
var result=JSONtoArray(jsondata[3].map_list);
// далее работаем с массивом
}
JSONParser parser = new JSONParser();
JSONObject obj;
try {
obj = (JSONObject) parser.parse(new FileReader("E:\\json.txt"));
out.println("<br>"+obj);
JSONObject jsonObject = (JSONObject) obj;
JSONArray from_excel = (JSONArray)jsonObject.get("from_excel");
// вариант построчного вывода 1
for(Object o: from_excel){
out.println("<br>"+o);
}
// вариант построчного вывода 2
Iterator iterator = from_excel.iterator();
while (iterator.hasNext()) {
out.println("<br>"+iterator.next());
}
// вариант поименного вывода 3
for (int i = 0; i < from_excel.size(); i++) {
JSONObject jsonObjectRow = (JSONObject) from_excel.get(i);
String num = (String) jsonObjectRow.get("num");
String solution = (String) jsonObjectRow.get("solution");
out.println("<br>num="+num+"; solution="+solution);
}
} catch (Exception e) {
out.println("Ошибка: "+e);
}
<%@ taglib prefix="json" uri="http://www.atg.com/taglibs/json" %>
<sql:query var="rs" dataSource="jdbc/ORACLE">
SELECT
to_char(r.TIME_STAMP, 'dd.mm.yyyy hh24:mi:ss') AS TIME_STAMP,
r.NAME AS COUNTER,
r.VALUE
FROM
profile_new r
WHERE
TIME_STAMP > to_date('25.07.2016 02:30:00', 'dd.mm.yyyy hh24:mi:ss')
and TIME_STAMP < to_date('25.07.2016 02:35:00', 'dd.mm.yyyy hh24:mi:ss')
order by time_stamp
</sql:query>
<c:set var="json_text" scope="application">
<json:array name="rows" prettyPrint="false">
<c:forEach var="row" items="${rs.rows}">
<json:object>
<json:property name="TIME_STAMP" value="${row.TIME_STAMP}"/>
<json:property name="COUNTER" value="${row.COUNTER}"/>
<json:property name="VALUE" value="${row.VALUE}"/>
</json:object>
</c:forEach>
</json:array>
</c:set>
[{"TIME_STAMP": "2016-07-25 02:30:22", "COUNTER": "COUNT_ALL", "VALUE": 635 }, { "TIME_STAMP": "2016-07-25 02:30:22", "COUNTER": "COUNT_BAD", "VALUE": 1 }, { "TIME_STAMP": "2016-07-25 02:30:22", "COUNTER": "QUALITY", "VALUE": 99.84 }, { "TIME_STAMP": "2016-07-25 02:31:22", "COUNTER": "COUNT_ALL", "VALUE": 642 }, { "TIME_STAMP": "2016-07-25 02:31:22", "COUNTER": "COUNT_BAD", "VALUE": 1 }, { "TIME_STAMP": "2016-07-25 02:31:22", "COUNTER": "QUALITY", "VALUE": 99.84 }]
<script type="text/javascript">
var jsonObj = ${json_text};
var jsonResult = [];
jsonResult.push("Вывод JSON="+'<c:out value="${json_text}"/>');
jsonResult.push("количество строк json="+jsonObj.length);
result_json.innerHTML = jsonResult.join('<br>');
</script>