我希望我的JSON看起来像这样:
{
"information": [{
"timestamp": "xxxx",
"feature": "xxxx",
"ean": 1234,
"data": "xxxx"
}, {
"timestamp": "yyy",
"feature": "yyy",
"ean": 12345,
"data": "yyy"
}]
}
Run Code Online (Sandbox Code Playgroud)
代码到目前为止:
import java.util.List;
public class ValueData {
private List<ValueItems> information;
public ValueData(){
}
public List<ValueItems> getInformation() {
return information;
}
public void setInformation(List<ValueItems> information) {
this.information = information;
}
@Override
public String toString() {
return String.format("{information:%s}", information);
}
}
Run Code Online (Sandbox Code Playgroud)
和
public class ValueItems {
private String timestamp;
private String feature;
private int ean;
private String data; …Run Code Online (Sandbox Code Playgroud) 当我使用JAVA时,我的页面跳转有问题,如果我使用:
response.sendRedirect("login.jsp")
Run Code Online (Sandbox Code Playgroud)
然后我得到这个网址: http://localhost:8080/login.jsp
但是,如果我使用
request.getRequestDispathcer("login.jsp").forward(request, response)
Run Code Online (Sandbox Code Playgroud)
然后我得到这个网址:( http://localhost:8080/Shopping/login.jsp"购物"是我模块的名称).
有什么不同?
如何使用JavaScript获取JSON对象中的键值和对象的长度.
例如:
[
{
"amount": " 12185",
"job": "GAPA",
"month": "JANUARY",
"year": "2010"
},
{
"amount": "147421",
"job": "GAPA",
"month": "MAY",
"year": "2010"
},
{
"amount": "2347",
"job": "GAPA",
"month": "AUGUST",
"year": "2010"
}
]
Run Code Online (Sandbox Code Playgroud)
这里,这个数组的长度是3.为了获得值很好([0].amount),在索引中[0]它有3个名称值对.
所以,我需要得到这个名字(比如数量或工作......总共有四个名字),还要算出有多少名字?
我正在开发一个j2ee应用程序.在我的应用程序中,我有一个下拉列表(或选择元素).我想用JSON数据填充这个下拉列表作为Ajax响应.
以下是我的代码:
服务器端代码(json_source.java),它生成JSON响应.:
package demo.model;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.*;
/**
* Servlet implementation class json_source
*/
public class json_source extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
JsonArray data_json=new JsonArray();
Statement st_loginId=null;
ResultSet rs_loginId=null;
try
{
Connection con=null;
Class.forName("oracle.jdbc.OracleDriver");
/* Connection String for "OPERWH"(exadata) …Run Code Online (Sandbox Code Playgroud) 我正在创建并解雇NSTimer:
ncTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(handleTimer:)
userInfo:nil
repeats:YES];
[ncTimer fire];
Run Code Online (Sandbox Code Playgroud)
和
- (void)handleTimer:(NSTimer *)chkTimer {
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
我保留我的计时器:
@property (nonatomic, retain) NSTimer *ncTimer;
Run Code Online (Sandbox Code Playgroud)
由于某种原因,计时器不重复.它只发射一次而不是再发射一次.
FHSTwitterEngine *engine = [FHSTwitterEngine sharedEngine];
[engine clearAccessToken];
Run Code Online (Sandbox Code Playgroud)
我试过上面的代码但是当我再次尝试登录时,textfields没有presentModalViewController显示,它显示了授权应用程序按钮.
还有另一种方法, [engine clearConsumer];这导致Select and Copy the PIN在presentModalViewController
我正在Eclipse中使用maven项目为sonarqube创建一个新的语言插件,并在构建项目时面临以下错误:
Failed to execute goal com.mycila.maven-license-plugin:maven-license-plugin:1.9.0:
check (enforce-license-headers) on project sonar-java-plugin:
Some files do not have the expected license header -> [Help 1]
Run Code Online (Sandbox Code Playgroud) 我有一个安静的Web服务,响应是:
{
"cities": [{
"id": "1",
"name": "City 01",
"state": "A1"
}, {
"id": "2",
"name": "City 02",
"state": "A1"
}]
}
Run Code Online (Sandbox Code Playgroud)
但我想要这个:
{
[{
"id": "1",
"name": "City 01",
"state": "A1"
}, {
"id": "2",
"name": "City 02",
"state": "A1"
}]
}
Run Code Online (Sandbox Code Playgroud)
我如何配置JAX-RS只使用JAX-RS功能而不是根节点生成JSON,而不是实现特定功能?我的代码需要可以在任何appserver上移植.
我正在尝试3.0的android操作栏,我参考
http://www.youtube.com/watch?v=gMu8XhxUBl8
代码TabsActivity如下:
package com.test.actionbar;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
public class TabsActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tabA = bar.newTab().setText("A Tab");
ActionBar.Tab tabB = bar.newTab().setText("B Tab");
ActionBar.Tab tabC = bar.newTab().setText("C Tab");
Fragment fragmentA = new AFragmentTab();
Fragment fragmentB = new BFragmentTab();
Fragment fragmentC = new CFragmentTab();
tabA.setTabListener(new MyTabsListener(fragmentA));
tabB.setTabListener(new MyTabsListener(fragmentB));
tabC.setTabListener(new MyTabsListener(fragmentC));
bar.addTab(tabA);
bar.addTab(tabB);
bar.addTab(tabC);
}
protected class MyTabsListener implements …Run Code Online (Sandbox Code Playgroud) tabs android runtimeexception android-3.0-honeycomb android-actionbar
我有以下格式的JSON,我正在尝试写入CSV:
{
"results": [{
"geo_position": {
"Field1": 11,
"Filed2": 12
},
"Field3": 13,
"Filed4": 14,
"Field5": 15
},
{
"geo_position": {
"Field1": 21,
"Filed2": 22
},
"Field3": 23,
"Filed4": 24,
"Filed5": 25
}
]
}
Run Code Online (Sandbox Code Playgroud)
我期待输出像:
field1,field2,field3,field4,field5
11,12,13,14,15
21,22,23,24,25
Run Code Online (Sandbox Code Playgroud)
我得到输出CSV如下:
geo_position,field3,field4,field5
{Field1:11,Field2:12}, 13,14,15
{Field2:21,Field2:22},23,24,25
Run Code Online (Sandbox Code Playgroud)
我的java代码:
JSONObject jsonObj = new JSONObject(jsonArray);
System.out.println(jsonObj);
JSONArray docs = jsonObj.getJSONArray("results");
File file=new File("C:/fromJSON2.csv");
String csv = CDL.toString(docs);
FileUtils.writeStringToFile(file, csv);
Run Code Online (Sandbox Code Playgroud)
有人可以帮我弄清楚为什么我会采用不同的格式.我应该怎么做以达到我期望的格式?