- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 android studio 和 json 的新手。我在 Android Studio 中有一个项目,其中我从服务器获取数据并将数据发送到服务器。
我在向服务器发送数据时遇到问题。数据是对象类型,当我将数据放入 jsonObject 时,数据发送混合,并且我没有收到正确的数据(我发送的)。这是我从服务器获取的对象:
{
"success": true,
"body": {
"priority1": {
"timeTable": {
"fri": false,
"time": {
"op": true,
"cl": false,
"fh": null,
"fm": null,
"th": null,
"tm": null
},
"mon": true,
"sat": true,
"sun": false,
"thu": false,
"tue": true,
"wed": true
},
"number": "12345612332",
"timeOut": "1"
},
"priority2": {
"timeTable": {
"fri": false,
"time": {
"op": true,
"cl": false,
"fh": null,
"fm": null,
"th": null,
"tm": null
},
"mon": true,
"sat": true,
"sun": false,
"thu": true,
"tue": false,
"wed": true
},
"number": "12345678901",
"timeOut": "5"
},
"priority3": {
"timeTable": {
"time": {
"op": true,
"cl": false,
"fh": null,
"fm": null,
"th": null,
"tm": null
},
"mon": true,
"tue": true,
"wed": true,
"thu": true,
"fri": true,
"sat": true,
"sun": true
},
"number": null,
"timeOut": null
},
"priority4": {
"timeTable": {
"time": {
"op": true,
"cl": false,
"fh": null,
"fm": null,
"th": null,
"tm": null
},
"mon": true,
"tue": true,
"wed": true,
"thu": true,
"fri": true,
"sat": true,
"sun": true
},
"number": null,
"timeOut": null
},
"priority5": {
"timeTable": {
"time": {
"op": true,
"cl": false,
"fh": null,
"fm": null,
"th": null,
"tm": null
},
"mon": true,
"tue": true,
"wed": true,
"thu": true,
"fri": true,
"sat": true,
"sun": true
},
"number": null,
"timeOut": null
}
},
"error": null
}
这是我发送到服务器的对象:
{
"priority5": {
"number": null,
"timeOut": null,
"timeTable": {
"fri": true,
"mon": true,
"sat": true,
"sun": true,
"thu": true,
"time": {
"cl": false,
"fh": null,
"fm": null,
"op": true,
"th": null,
"tm": null
},
"tue": true,
"wed": true
}
},
"priority4": {
"number": null,
"timeOut": null,
"timeTable": {
"fri": true,
"mon": true,
"sat": true,
"sun": true,
"thu": true,
"time": {
"cl": false,
"fh": null,
"fm": null,
"op": true,
"th": null,
"tm": null
},
"tue": true,
"wed": true
}
},
"priority1": {
"number": "12345612332",
"timeOut": "1",
"timeTable": {
"fri": false,
"mon": true,
"sat": true,
"sun": false,
"thu": false,
"time": {
"cl": false,
"fh": null,
"fm": null,
"op": true,
"th": null,
"tm": null
},
"tue": true,
"wed": true
}
},
"priority3": {
"number": null,
"timeOut": null,
"timeTable": {
"fri": true,
"mon": true,
"sat": true,
"sun": true,
"thu": true,
"time": {
"cl": false,
"fh": null,
"fm": null,
"op": true,
"th": null,
"tm": null
},
"tue": true,
"wed": true
}
},
"priority2": {
"number": "12345678901",
"timeOut": "5",
"timeTable": {
"fri": false,
"mon": true,
"sat": true,
"sun": false,
"thu": true,
"time": {
"cl": false,
"fh": "02",
"fm": "04",
"op": false,
"th": "08",
"tm": "03"
},
"tue": false,
"wed": true
}
}
}
这是我将数据放入 jsonObject 的 set 方法:
私有(private)无效setExtensionForwardNumber(){
if(priorityOne.isChecked()) {
if (validateNumberField(priorityOneNumber)) {
priorityResponse.priorityOne.number = priorityOneNumber.getText().toString();
priorityResponse.priorityOne.timeOut = priorityOneTimeOut.getText().toString();
priorityResponse.priorityOne.getTimeTable().mon = priorityOneMon.isChecked();
priorityResponse.priorityOne.getTimeTable().tue = priorityOneTue.isChecked();
priorityResponse.priorityOne.getTimeTable().wed = priorityOneWed.isChecked();
priorityResponse.priorityOne.getTimeTable().thu = priorityOneThur.isChecked();
priorityResponse.priorityOne.getTimeTable().fri = priorityOneFri.isChecked();
priorityResponse.priorityOne.getTimeTable().sat = priorityOneSat.isChecked();
priorityResponse.priorityOne.getTimeTable().sun = priorityOneSun.isChecked();
priorityResponse.priorityOne.getTimeTable().getTime().open = priorityOne.isChecked();
priorityResponse.priorityOne.getTimeTable().getTime().open = priorityOne24h.isChecked();
if (!priorityOne24h.isChecked()) {
priorityResponse.priorityOne.getTimeTable().getTime().fromHour = priorityOneFromHours.getSelectedItem().toString();
priorityResponse.priorityOne.getTimeTable().getTime().fromMinute = priorityOneFromMinutes.getSelectedItem().toString();
priorityResponse.priorityOne.getTimeTable().getTime().toHour = priorityOneToHours.getSelectedItem().toString();
priorityResponse.priorityOne.getTimeTable().getTime().toMinute = priorityOneToMinute.getSelectedItem().toString();
}
}
}else{
priorityOne.setEnabled(false);
}
if(priorityTwo.isChecked()){
if(validateNumberField(priorityTwoNumber)){
priorityResponse.priorityTwo.number =priorityTwoNumber.getText().toString();
priorityResponse.priorityTwo.timeOut = priorityTwoTimeOut.getText().toString();
priorityResponse.priorityTwo.getTimeTable().mon = priorityTwoMon.isChecked();
priorityResponse.priorityTwo.getTimeTable().tue = priorityTwoTue.isChecked();
priorityResponse.priorityTwo.getTimeTable().wed = priorityTwoWed.isChecked();
priorityResponse.priorityTwo.getTimeTable().thu = priorityTwoThur.isChecked();
priorityResponse.priorityTwo.getTimeTable().fri = priorityTwoFri.isChecked();
priorityResponse.priorityTwo.getTimeTable().sat = priorityTwoSat.isChecked();
priorityResponse.priorityTwo.getTimeTable().sun = priorityTwoSun.isChecked();
priorityResponse.priorityTwo.getTimeTable().getTime().open = priorityTwo.isChecked();
priorityResponse.priorityTwo.getTimeTable().getTime().open = priorityTwo24h.isChecked();
if(!priorityTwo24h.isChecked()){
priorityResponse.priorityTwo.getTimeTable().getTime().fromHour = priorityTwoFromHours.getSelectedItem().toString();
priorityResponse.priorityTwo.getTimeTable().getTime().fromMinute = priorityTwoFromMinutes.getSelectedItem().toString();
priorityResponse.priorityTwo.getTimeTable().getTime().toHour = priorityTwoToHours.getSelectedItem().toString();
priorityResponse.priorityTwo.getTimeTable().getTime().toMinute = priorityTwoToMinute.getSelectedItem().toString();
}
}
}else{
priorityTwo.setEnabled(false);
}
if(priorityThree.isChecked()){
if(validateNumberField(priorityThreeNumber)){
priorityResponse.priorityThree.number =priorityTwoNumber.getText().toString();
priorityResponse.priorityThree.timeOut = priorityTwoTimeOut.getText().toString();
priorityResponse.priorityThree.getTimeTable().mon = priorityThreeMon.isChecked();
priorityResponse.priorityThree.getTimeTable().tue = priorityThreeTue.isChecked();
priorityResponse.priorityThree.getTimeTable().wed = priorityThreeWed.isChecked();
priorityResponse.priorityThree.getTimeTable().thu = priorityThreeThur.isChecked();
priorityResponse.priorityThree.getTimeTable().fri = priorityThreeFri.isChecked();
priorityResponse.priorityThree.getTimeTable().sat = priorityThreeSat.isChecked();
priorityResponse.priorityThree.getTimeTable().sun = priorityThreeSun.isChecked();
priorityResponse.priorityThree.getTimeTable().getTime().open = priorityThree.isChecked();
priorityResponse.priorityThree.getTimeTable().getTime().open = priorityThree24h.isChecked();
if(!priorityThree24h.isChecked()){
priorityResponse.priorityThree.getTimeTable().getTime().fromHour = priorityThreeFromHours.getSelectedItem().toString();
priorityResponse.priorityThree.getTimeTable().getTime().fromMinute = priorityThreeFromMinutes.getSelectedItem().toString();
priorityResponse.priorityThree.getTimeTable().getTime().toHour = priorityThreeToHours.getSelectedItem().toString();
priorityResponse.priorityThree.getTimeTable().getTime().toMinute = priorityThreeToMinute.getSelectedItem().toString();
}
}
}else{
priorityThree.setEnabled(false);
}
if(priorityFour.isChecked()){
if(validateNumberField(priorityFourNumber)){
priorityResponse.priorityFour.number =priorityFourNumber.getText().toString();
priorityResponse.priorityFour.timeOut = priorityFourTimeOut.getText().toString();
priorityResponse.priorityFour.getTimeTable().mon = priorityFourMon.isChecked();
priorityResponse.priorityFour.getTimeTable().tue = priorityFourTue.isChecked();
priorityResponse.priorityFour.getTimeTable().wed = priorityFourWed.isChecked();
priorityResponse.priorityFour.getTimeTable().thu = priorityFourThur.isChecked();
priorityResponse.priorityFour.getTimeTable().fri = priorityFourFri.isChecked();
priorityResponse.priorityFour.getTimeTable().sat = priorityFourSat.isChecked();
priorityResponse.priorityFour.getTimeTable().sun = priorityFourSun.isChecked();
priorityResponse.priorityFour.getTimeTable().getTime().open = priorityFour.isChecked();
priorityResponse.priorityFour.getTimeTable().getTime().open = priorityFour24h.isChecked();
if(!priorityThree24h.isChecked()){
priorityResponse.priorityFour.getTimeTable().getTime().fromHour = priorityFourFromHours.getSelectedItem().toString();
priorityResponse.priorityFour.getTimeTable().getTime().fromMinute = priorityFourFromMinutes.getSelectedItem().toString();
priorityResponse.priorityFour.getTimeTable().getTime().toHour = priorityFourToHours.getSelectedItem().toString();
priorityResponse.priorityFour.getTimeTable().getTime().toMinute = priorityFourToMinute.getSelectedItem().toString();
}
}
}else{
priorityFour.setEnabled(false);
}
if(priorityFive.isChecked()){
if(validateNumberField(priorityFiveNumber)){
priorityResponse.priorityFive.number =priorityFiveNumber.getText().toString();
priorityResponse.priorityFive.timeOut = priorityFiveTimeOut.getText().toString();
priorityResponse.priorityFive.getTimeTable().mon = priorityFiveMon.isChecked();
priorityResponse.priorityFive.getTimeTable().tue = priorityFiveTue.isChecked();
priorityResponse.priorityFive.getTimeTable().wed = priorityFiveWed.isChecked();
priorityResponse.priorityFive.getTimeTable().thu = priorityFiveThur.isChecked();
priorityResponse.priorityFive.getTimeTable().fri = priorityFiveFri.isChecked();
priorityResponse.priorityFive.getTimeTable().sat = priorityFiveSat.isChecked();
priorityResponse.priorityFive.getTimeTable().sun = priorityFiveSun.isChecked();
priorityResponse.priorityFive.getTimeTable().getTime().open = priorityFive.isChecked();
priorityResponse.priorityFive.getTimeTable().getTime().open = priorityFive24h.isChecked();
if(!priorityThree24h.isChecked()){
priorityResponse.priorityFive.getTimeTable().getTime().fromHour = priorityFiveFromHours.getSelectedItem().toString();
priorityResponse.priorityFive.getTimeTable().getTime().fromMinute = priorityFiveFromMinutes.getSelectedItem().toString();
priorityResponse.priorityFive.getTimeTable().getTime().toHour = priorityFiveToHours.getSelectedItem().toString();
priorityResponse.priorityFive.getTimeTable().getTime().toMinute = priorityFiveToMinute.getSelectedItem().toString();
}
}
}else{
priorityFive.setEnabled(false);
}
String s = priorityResponse.toJsonObject();
setForwardExternalFragment(s);
}
请帮我解决我的问题。谢谢!
最佳答案
作为一般规则,JSON 对象不是为维护顺序而设计的。您应该使用键访问值,在这种情况下顺序无关紧要。
如果确实必须维持顺序,可以使用 JSON 数组。
关于java - 如何将有序数据放入jsonObject中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37975501/
我试图在 Eclipse v3.7.2 中将 loopj .jar 库添加到我的项目中 首先,我将 .jar 添加到“lib”目录中,右键单击它并选择“添加到构建路径”。它编译得很好,但在执行时出现错
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Passing two-dimensional array via pointer int table[20
我在 Grafana 中的图表每隔几秒钟就会自动更新一次。随着数据的进入,右侧的最后一个数据点会暂时下降。最终会显示正确的值,但在几次更新时该值较低。这是正常的吗?可以修复吗? 最佳答案 也许,这会有
我不明白为什么我会收到臭名昭著的“IllegalStateException”以及以下代码: private void mergeQueryStrings(String url, Map parame
您好,我正在通过 .php 文件中的 JSON 回显将测试 Android 应用程序链接到 MySQL 数据库。 我能够用整个数据填充 ArrayList,但现在我想将数据分离到变量中,但我无法真正找
我想仅将对象的数据成员的值写入文件,因此这里我不能使用序列化,因为它会写入很多内容其他我不需要的信息。这是我通过两种方式实现的。一种使用字节缓冲区,另一种则不使用它。 不使用 ByteBuffer:第
可能是个简单的问题,但我似乎找不到答案。我正在动态创建一个页面,我可以在其中共享 Twitter 链接。 var twitter = document.createElement('a'); tw
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
尝试获取我在末尾为 $_SESSION 设置的值作为查询中的 user_id,而不是 $username。我似乎无法修改查询。我确信这对于这里的一些专家来说是非常简单的。 if(isset($_POS
有没有人可以帮助我,我有 mysql 查询,我已经在 phpmyadmin 中测试了它: select items.name, items.category, items.supplier_id, i
我正在尝试 push_back()一个„ std::vector 的符号. 我一直收到错误: character too large for enclosing character literal t
我有一个存储在 char * 中的压缩图像,我想将它放回 AVPacket,以便我可以将它放入 ffmpeg 解码器。有人可以展示如何做到这一点吗?任何示例或教程将不胜感激。 提前致谢 最佳答案 我向
password = str() while password != "changeme": password = input("Password: ") print("Thou Shall
所以我有一个 Map,其中有一些值被传递到一个方法中: public String doThis(Map context){ ..... } 我正在尝试向该 map 插入附加属性 String abc
我遇到了一些我无法弄清楚的问题...我正在编写一个带有接受拖放的 JList 的 Swing Java 应用程序。我想在将文件或文件夹从我的系统拖到 Java 应用程序上时更改光标。 最佳答案 我自己
我正在尝试确定一些关于如何编写异常消息的指南。 例如,让我们假设一个假设的函数必须接收恒定数量的字节(作为 bytes 对象),我们用 [1, 2, 3]。以下是所有可能的异常(exception)情
使用 JSONObject 发送到网络服务当我们将 double(整数)放入零时,该点将被删除 代码 double d = 123.00; JSONObject json = new JSONObje
在 WPF 中,如何将 DataGrid 放在 ComboBox 中以显示多列?像下面这样的东西似乎没有做任何事情:
我正在尝试使用自定义 QStandardItem 在两个 QListViews 之间进行拖放。 除了this document,我在网上找不到我需要的信息这有点帮助,但现在我被困住了。 从一个 QLi
如何将 PDF 放入 NSData 中?我在应用程序的文档目录中以字符串形式找到了 PDF 的位置。当我尝试通过电子邮件发送时,我在电子邮件正文中看到 PDF(而不是看到附件图标。我不知道这是否正常)
我是一名优秀的程序员,十分优秀!