Tag: json

如何为这个SQL查询编写Hibernate Criteria?

我有一个像这样的查询 询问 SELECT attendance_entry.roll_no,attendance_entry.absent_date,attendance_entry.absent_status,attendance_entry.leave_status,attendance_entry.od_status FROM attendance,attendance_entry WHERE attendance.class_id='”+classId+”‘ && attendance.section_id='”+sectionId+”‘ && attendance_entry.absent_date= STR_TO_DATE(‘”+date+”‘,’%a %b %d %H:%i:%s IST %Y’) GROUP BY attendance_entry.roll_no”; 我需要为Parse Json写标准 我尝试了以下Criteria Criteria cr = getSession().createCriteria(AttendanceEntry.class) .setProjection(Projections.projectionList() .add(Projections.property(“rollno”),”rollno”) .add(Projections.property(“absent”),”absent”) .add(Projections.property(“leave”),”leave”) .add(Projections.property(“od”),”od”) .add(Projections.groupProperty(“rollno”),”rollno”)) .add(Restrictions.eq(“attendance.classYear.id”, classId)) .add(Restrictions.eq(“attendance.section.id”, sectionId)) .add(Restrictions.eq(“absentDate”, date)) .setResultTransformer(Transformers.aliasToBean(AttendanceEntry.class)); return cr.list(); 我有以下错误 错误 could not resolve property: attendance.classYear.id of: com.technofolks.model.AttendanceEntry; nested exception is […]

如何在“之前/之后”获得“时差”? 这可能不使用任何库吗?

我想将当前日期(YYYY-MM-DD)和时间(SS:MM:HH)的格式更改为’n’个月前,’n’天前,’n’小时“以前”格式。 当前格式: 要求的格式: 我使用Bean和Adapter类来获取当前日期。 代码如下; 适配器类 : public class MessageAdapter extends BaseAdapter { private Activity activity; private List messageBeanList; public ImageLoader imageLoader; private Context context; public MessageAdapter (Activity activity,List messageBeanList) { super(); this.activity = activity; // this.context = context; this.messageBeanList = messageBeanList; this.context=context; } @Override public int getCount() { return messageBeanList.size(); } @Override public Object […]

将SOAP响应转换为JSONArray

我有SOAP响应如下。 我想迭代soap消息,并希望以JSONArray格式获取listMetadataResponse标记中的数据。 这是我的SOAP响应示例: 00528000001m5RRAAY Hariprasath Thanarajah 1970-01-01T00:00:00.000Z objects/EmailMessage.object EmailMessage 00528000001m5RRAAY Hariprasath Thanarajah 1970-01-01T00:00:00.000Z CustomObject 00528000001m5RRAAY Hariprasath Thanarajah 1970-01-01T00:00:00.000Z objects/EmailMessage.object EmailMessage 00528000001m5RRAAY Hariprasath Thanarajah 1970-01-01T00:00:00.000Z CustomObject 我希望将每个结果节点作为JSONObject与每个属性节点和值作为JSON中的键值对进行。在这种情况下,我希望结果为JSONArray,其中包含两个结果JSONObject。 我试过这段代码。 我正在获取节点名称,但我没有得到节点值。 private static Document loadXMLString(String response) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(response)); return db.parse(is); } public static […]

Java对象用jackson将列表扩展到Json

我想使用Jackson将扩展列表的对象转换为Json。 例: public class TryToSerialize extends ArrayList { private int number; private String word; public TryToSerialize(){ number = 0; word = “”; } @JsonProperty public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } @JsonProperty public String getWord() { return word; } public void setWord(String word) { this.word = […]

Http Gateways和Json Transformers:剥离的标题

使用Spring Integration 4.0.3.RELEASE和Jackson2,我试图将Json Transformers与http网关结合使用。 我的路径看起来类似于Spring Integration文档中引用的amqp适配器,但是使用http gateways(1): …->对象到JSON-变压器 – > HTTP的出站网关—-> —-> HTTP的入站网关 – > JSON到对象的变压器 – > 客户: … 服务器: … 我得到的例外是(我认为相关的是粗体): 2014-08-22T23:58:21.640-0400 WARN [http-bio-8080-exec-2] osihiHttpRequestHandlingMessagingGateway网关发生故障sendAndReceive org.springframework.integration.transformer.MessageTransformationException:无法在org.springframework.integration上转换消息。 transform.AbstractTransformer.transform(AbstractTransformer.java:44)〜[spring-integration-core-4.0.3.RELEASE.jar:na] at org.springframework.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:68)〜 [spring-integration-core-4.0.3.RELEASE.jar:na] at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:170)~ [spring-integration-core-4.0.3.RELEASE。 jar:na] at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)〜[spring-integration-core-4.0.3.RELEASE.jar:na] at org.springframework.integration.handler。 MessageHandlerChain.ha ndleMessageInternal(MessageHandlerChain.java:131)〜[spring-integration-core-4.0.3.RELEASE.jar:na] at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)〜[spring-integration -core-4.0.3.RELEASE.jar:na] at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)~ [spring-integration-core-4.0.3.RELEASE.jar:na]在org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101)〜[spring-integration-core-4.0.3.RELEASE.jar:na] org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch( UnicastingDispatcher.java:97)〜[spring-integration-core-4.0.3.RELEASE.jar:na] org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)〜[spring-integration-core -4.0.3.RELEASE.jar:na] at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:255)~ [spring-integration-core-4.0.3.RELEASE.jar:na] […]

在servlet中创建json对象

我想将检索到的数据从服务器发送到我的Android客户端…我使用了一个json对象来做到这一点。 这是我的servlet代码。 import java.io.IOException; import java.io.PrintWriter; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONArray; import net.sf.json.JSONObject; public class AvailabilityResponse extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(“application/json”); PrintWriter out=response.getWriter(); String […]

如何在Struts 2中使用JSP返回JSON结果

我知道在Struts2中可以使用json插件来返回json类型的结果。 也可以像在这个答案中那样从stream结果中返回一个json 。 在使用JSP的Ajax结果的Struts2 docs页面上,我发现可以使用输出JSON的JSP返回dispatcher类型结果。 但它正在使用scriptlet将JSON写入out。 我知道在JSP中使用scriplet非常气馁。 但我在这个问题中找不到我的问题的答案如何避免JSP文件中的Java代码? 。 如何使用JSP结果生成JSON对象? 有没有更好的方法从JSP返回JSON对象?

解析json的问题

我必须解析这个json: { success: true, outputScenario: “Default”, data: { output: [ { titolo: “Lunedì 6 novembre”, sottotitolo: “Pesanti illazioni sulla conoscenza pregressa tra Vittoria e Mattia. Una nuova conoscenza per Paolo. E…”, date: “06/11/2017” }, { titolo: “I vincitori di Maria Express”, sottotitolo: “Loro sono…”, date: “06/11/2017” }, { titolo: “Mattia e Vittoria”, sottotitolo: “Mattia viene […]

通过使用Gson.fromJson()方法将json解析为类模型是行不通的

我的问题是,我不能通过使用Gson.fromJson()方法解析json到class 模型。 在我的PageOutput.java中 public class PageOutput { @SerializedName(“TotalItemCount”) public int totalItemCount; @SerializedName(“Items”) private T[] items; public final T[] getItems() { return items; } } 在Property.java中 public class Property { @SerializedName(“Id”) public String id; @SerializedName(“Title”) public String title; @SerializedName(“Price”) public BigDecimal price; …. } 在Main.java中 , PageOutput output = new Gson.fromJson(jsonString, new TypeToken<PageOutput>(){}.getType()); 编译项目时,我在Items中得到null。 但是当我使用时 PageOutput […]

使用Spring和Jackson JSON将java.io.Serializable实例序列化为JSON

我从一些内部API获取Serializable的实例。 Serializable实例实际上是Long或String等。有没有办法制作可以处理这种情况的DTO? 使用private Serializable value; JSON以value: {} 。 UPDATE 以下是相关代码的简化示例: @Controller public class SomeController { //… public MyDto getInfo(Long id) { MyDto result = new MyDto(); Serializable obj = svc.getInfo(id); // obj is either Long, or String, or one of few more fundamental Java types result.setValue(obj); return result; } } public class MyDto { private […]