- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是安卓新手。如何从服务器数据动态填充微调器。
所以我正在尝试将数据从服务器填充到我的微调器中。我的 JSON 是
{"topic": "/waypoints", "msg": {"waypoints": [{"header": {"stamp": {"secs": 0, "nsecs": 0}, "frame_id": "map", "seq": 0}, "pose": {"position": {"y": -140.901899144836, "x": 44.36469369653882, "z": 0.0}, "orientation": {"y": 0.0, "x": 0.0, "z": 0.5062775131960053, "w": 0.8623706161692133}}, "name": "A"}, {"header": {"stamp": {"secs": 0, "nsecs": 0}, "frame_id": "map", "seq": 0}, "pose": {"position": {"y": -102.30524463734227, "x": 51.282396271771304, "z": 0.0}, "orientation": {"y": 0.0, "x": 0.0, "z": 0.6926372547579506, "w": 0.721286096719859}}, "name": "B"}]}, "op": "publish"}
现在我试图只获取“名称”: A 和 B ,当我选择它们中的每一个时,将会有方向和位置的信息。提前致谢!
编辑
所以基本上这是我的航点的弹出窗口。我正在努力修复我的方法部分的“(String json)”。
public class Pop extends Activity {
private SubscribedData<WaypointList> waypointlistData;
private RosbridgeListener rosbridge;
Spinner spin;
String json;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.popup);
/** an ID for the spinner **/
spin = (Spinner) findViewById(R.id.spinner);
/** publisher definition with its type of message**/
waypointlistData = new SubscribedData<>();
final Type waypointlistType = new TypeToken<SubscribedData<WaypointList>>() {
}.getType();
/** A method to parse a jsonstring to waypoint list **/
private List<Waypoint> getWayPointListFromJsonString(String json){
List<Waypoint> wayPoints = new ArrayList<>();
try {
JSONObject jsonObject = new JSONObject(json);
JSONArray wayPointJsonArray = jsonObject.getJSONObject("msg").getJSONArray("waypoints");
for (int i = 0; i < wayPointJsonArray.length(); i++) {
JSONObject wayPointJsonObject = wayPointJsonArray.getJSONObject(i);
// Parse name
String name = wayPointJsonObject.getString("name");
// Parse pose to get position and orientation;
JSONObject poseJsonObject = wayPointJsonObject.getJSONObject("pose");
// Parse position form pose
JSONObject positionJsonObject = poseJsonObject.getJSONObject("position");
Position position = new Position();
position.x = positionJsonObject.getFloat("x");
position.y = positionJsonObject.getFloat("y");
position.z = positionJsonObject.getFloat("z");
// Parse orientation from pose.
JSONObject orientationJsonObject = poseJsonObject.getJSONObject("orientation");
Orientation orientation = new Orientation();
orientation.x = orientationJsonObject.getFloat("x");
orientation.y = orientationJsonObject.getFloat("y");
orientation.z = orientationJsonObject.getFloat("z");
orientation.w = orientationJsonObject.getFloat("w");
Pose pose = new Pose();
pose.position = position;
pose.orientation = orientation;
Waypoint wayPoint = new Waypoint();
wayPoint.name = name;
wayPoint.pose = pose;
wayPoints.add(wayPoint);
}
} catch (JSONException e) {
e.printStackTrace();
}
return wayPoints;
}
// This is the json string returned from server.
String jsonString = "{\"topic\": \"/waypoints\", \"msg\": {\"waypoints\": [{\"header\": {\"stamp\": {\"secs\": 0, \"nsecs\": 0}, \"frame_id\": \"map\", \"seq\": 0}, \"pose\": {\"position\": {\"y\": -140.901899144836, \"x\": 44.36469369653882, \"z\": 0.0}, \"orientation\": {\"y\": 0.0, \"x\": 0.0, \"z\": 0.5062775131960053, \"w\": 0.8623706161692133}}, \"name\": \"A\"}, {\"header\": {\"stamp\": {\"secs\": 0, \"nsecs\": 0}, \"frame_id\": \"map\", \"seq\": 0}, \"pose\": {\"position\": {\"y\": -102.30524463734227, \"x\": 51.282396271771304, \"z\": 0.0}, \"orientation\": {\"y\": 0.0, \"x\": 0.0, \"z\": 0.6926372547579506, \"w\": 0.721286096719859}}, \"name\": \"B\"}]}, \"op\": \"publish\"}";
// This will convert the json string to list of WayPoint
List<Waypoint> wayPoints = getWayPointListFromJsonString(jsonString);
// Create adapter for spinner
SpinnerAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, wayPoints);
spin.setAdapter(adapter);
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int p, long id) {
Waypoint wayPoint = (Waypoint) parent.getItemAtPosition(p);
// Process position here
Position position = wayPoint.pose.position;
// Process orientation here
Orientation orientation = wayPoint.pose.orientation;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
/** a set of the waypoints popup window **/
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int) (width * .6), (int) (height * .6));
}
}
最佳答案
微调器中的每一项都表示一个“WayPoint”。所以第一步是为 WayPoint 创建模型类。
class WayPoint {
String name;
Pose pose;
@NonNull
@Override
public String toString() {
return name;
}
}
class Pose {
Position position;
Orientation orientation;
}
class Position {
double x, y, z;
}
class Orientation {
double x, y, z, w;
}
其次,编写一个方法来解析json字符串到航点列表
private List<WayPoint> getWayPointListFromJsonString(String json) {
List<WayPoint> wayPoints = new ArrayList<>();
try {
JSONObject jsonObject = new JSONObject(json);
JSONArray wayPointJsonArray = jsonObject.getJSONObject("msg").getJSONArray("waypoints");
for (int i = 0; i < wayPointJsonArray.length(); i++) {
JSONObject wayPointJsonObject = wayPointJsonArray.getJSONObject(i);
// Parse name
String name = wayPointJsonObject.getString("name");
// Parse pose to get position and orientation;
JSONObject poseJsonObject = wayPointJsonObject.getJSONObject("pose");
// Parse position form pose
JSONObject positionJsonObject = poseJsonObject.getJSONObject("position");
Position position = new Position();
position.x = positionJsonObject.getDouble("x");
position.y = positionJsonObject.getDouble("y");
position.z = positionJsonObject.getDouble("z");
// Parse orientation from pose.
JSONObject orientationJsonObject = poseJsonObject.getJSONObject("orientation");
Orientation orientation = new Orientation();
orientation.x = orientationJsonObject.getDouble("x");
orientation.y = orientationJsonObject.getDouble("y");
orientation.z = orientationJsonObject.getDouble("z");
orientation.w = orientationJsonObject.getDouble("w");
Pose pose = new Pose();
pose.position = position;
pose.orientation = orientation;
WayPoint wayPoint = new WayPoint();
wayPoint.name = name;
wayPoint.pose = pose;
wayPoints.add(wayPoint);
}
} catch (JSONException e) {
e.printStackTrace();
}
return wayPoints;
}
最后将它们放入MainActivity类中。
public class MainActivity extends AppCompatActivity {
private Spinner wayPointSpinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wayPointSpinner = findViewById(R.id.spinner_way_point);
// This is the json string returned from server.
String jsonString = "{\"topic\": \"/waypoints\", \"msg\": {\"waypoints\": [{\"header\": {\"stamp\": {\"secs\": 0, \"nsecs\": 0}, \"frame_id\": \"map\", \"seq\": 0}, \"pose\": {\"position\": {\"y\": -140.901899144836, \"x\": 44.36469369653882, \"z\": 0.0}, \"orientation\": {\"y\": 0.0, \"x\": 0.0, \"z\": 0.5062775131960053, \"w\": 0.8623706161692133}}, \"name\": \"A\"}, {\"header\": {\"stamp\": {\"secs\": 0, \"nsecs\": 0}, \"frame_id\": \"map\", \"seq\": 0}, \"pose\": {\"position\": {\"y\": -102.30524463734227, \"x\": 51.282396271771304, \"z\": 0.0}, \"orientation\": {\"y\": 0.0, \"x\": 0.0, \"z\": 0.6926372547579506, \"w\": 0.721286096719859}}, \"name\": \"B\"}]}, \"op\": \"publish\"}";
// This will convert the json string to list of WayPoint
List<WayPoint> wayPoints = getWayPointListFromJsonString(jsonString);
// Create adapter for spinner
SpinnerAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, wayPoints);
wayPointSpinner.setAdapter(adapter);
wayPointSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int p, long id) {
WayPoint wayPoint = (WayPoint) parent.getItemAtPosition(p);
// Process position here
Position position = wayPoint.pose.position;
// Process orientation here
Orientation orientation = wayPoint.pose.orientation;
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
关于java - Android:动态填充来自服务器的微调器数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58090172/
有没有人对如何解决这个查询有任何想法? 有一张客户表和一张许可证表。每个客户可以有多个在不同时间到期的许可证,一些已经过期,一些还没有。如果我想选择至少拥有一个有效许可证的所有客户,我会这样做: SE
我一直在尝试微调 HuggingFace: Blendebot 的对话模型。我已经尝试过拥抱脸官方网站上给出的常规方法,它要求我们使用 trainer.train() 方法来完成。我也尝试过使用 .c
是否有内置的 JavaScript 字符串方法可以帮助我微调这段代码以确保它只找到与名称完全匹配的内容? 这是我的代码。 /*jshint multistr:true */ var text = "S
我需要微调我的 word2vec 模型。我有两个数据集,data1 和 data2。 到目前为止我所做的是: model = gensim.models.Word2Vec( data1
在苹果的应用程序中,我注意到滚动效果非常完美。一切都进展顺利,当你停下来时,它就停止了。您可以拥有一个巨大的图像并直接移动到任何位置,并且它会停留在那里。 我想提供相同的 UE,但对于我的应用程序,如
问题 请帮助理解以下问题的原因以及如何构建 Keras 模型以在 huggingface 的预训练模型之上进行微调。 目标 在 TFDistilBertForSequenceClassificatio
我正在尝试为不同的数据集和不同的算法绘制一堆 ROC 区域。 我有三个变量:“Scheme”指定使用的算法,“Dataset”是测试算法的数据集,以及“Area_under_ROC”。 我在 R 中使
我正在使用 CNN 进行面部表情识别。我使用 Keras 和 Tensorflow 作为后端。我的模型保存为 h5 格式。 我想重新训练我的网络,并使用 VGG 模型微调我的模型。 我如何使用 ker
我正在使用 NSControlTextEditingDelegate 自动完成内容在 NSSearchField 中输入我生成的自定义建议。complete: 消息发送到字段编辑器当文本更改时。 现在
我为 mnist 数据集开发了一个 3 层深度自动编码器模型,因为我只是这个微调范例的初学者,所以我正在练习这个玩具数据集 下面是代码 from keras import layers from k
在我的代码中有一个我正在计算的参数。在多次测试中,该参数应该为0。由于该参数是通过多次加减计算的,因此不完全为0,而是小于10^-10。目前我正在使用: double tol = pow(10,-10
我的应用程序中有一个微调器,但在单击某个项目时它不起作用。我得到了值,但 if 条件不起作用。 spinner.setOnItemSelectedListener(new AdapterView.On
我需要帮助调整我的 mysql 服务器以获得更好的性能。我有很多资源,但它仍然表现不佳。我打得最多的一张表只有350万条记录。 我需要帮助关注更改哪些设置以获得更好的性能。 像这样的简单查询 SELE
在keras blog上有一个VGG16微调的例子,但我无法重现它。 更准确地说,这里是用于在没有顶层的情况下初始化 VGG16 并卡住除最顶层以外的所有 block 的代码: WEIGHTS_PAT
我正在尝试创建一个 Activity RateCardActivity,其中有一个微调器。 RateCardActivity 的布局文件是 rate_card。我的 RateCardActivity
微调器 xml: 我试过使用 android:background=... 自己购买,使用 dropDownSelector,使用和不使用 listSelector=...; 使用和不使用 list
我精心制作了下面列出组成员的命令: gwmi win32_group -filter 'Name="Administrators"'|%{$_.GetRelated('Win32_UserAccoun
已成功构建 HTML5 应用程序。以下库用于此: jquery.mobile-1.1.1.min.js jquery.mobile-1.1.1.min lawnchair.js 一切正常用 Phone
我在使用 Keras 微调 Inception 模型时遇到问题。 我已经成功地使用教程和文档生成了一个完全连接的顶层模型,该模型使用 Inception 中的瓶颈特征将我的数据集分类到正确的类别中,准
我对 PyTorch 和 Huggingface-transformers 比较陌生,并在此 Kaggle-Dataset 上试验过 DistillBertForSequenceClassificat
我是一名优秀的程序员,十分优秀!