java实现"["be0e2540-3c49-11ec-abdc-7ba81cf6c5ef"]"去除[]以及两个双引号
时间: 2023-11-21 19:10:22 浏览: 106
可以通过以下代码实现:
```
String str = "\"[be0e2540-3c49-11ec-abdc-7ba81cf6c5ef]\"";
str = str.replace("[", "").replace("]", "").replace("\"", "");
System.out.println(str);
```
输出结果为:
```
be0e2540-3c49-11ec-abdc-7ba81cf6c5ef
```
相关问题
DirectoryNotFoundException: Could not find a part of the path "/var/mobile/Containers/Data/Application/520AF0D7-ABDC-45F4-A3D6-703449F1847A/Documents/Logs/20230524202024.log". at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x00000] in <00000000000000000000000000000000>:0 at System.IO.File.Create (System.String path, System.Int32 bufferSize) [0x00000] in <00000000000000000000000000000000>:0 at CosLog.OnLogCallBack (System.String condition, System.String stackTrace, UnityEngine.LogType type) [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.Application.CallLogCallback (System.String logString, System.String stackTrace, UnityEngine.LogType type, System.Boolean invokedOnMainThread) [0x00000] in <00000000000000000000000000000000>:0 at CosmosAR.FsmSceneARInitialize+<Prepare>d__5.MoveNext () [0x00000] in <00000000000000000000000000000000>:0 at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00000] in <00000000000000000000000000000000>:0 CosmosAR.<Prepare>d__5:MoveNext() UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)
这个错误是指在路径 "/var/mobile/Containers/Data/Application/520AF0D7-ABDC-45F4-A3D6-703449F1847A/Documents/Logs/20230524202024.log" 找不到相应的文件。可能是文件被删除或移动了,或者路径不正确。需要检查路径和文件是否存在。
使用RestTemplate的POST请求http://www.ousuiot.com:9801/querypubdata,用实体类接收结果集 请求参数: { "signature":"FC73D944C6E54087ABDC3F71AD7857BF", "deviceid":"230417100002" } 请求结果: {"code":200,"deviceid":"230417100002","data":[{"channelid":1,"devname":"温度","devvalue":"35.3","devunit":"℃","devtime":"2023-06-02 16:18:54"},{"channelid":2,"devname":"湿度","devvalue":"46.6","devunit":"%RH","devtime":"2023-06-02 16:18:54"},{"channelid":3,"devname":"光照度","devvalue":"8960","devunit":"Lux","devtime":"2023-06-02 16:18:54"},{"channelid":4,"devname":"二氧化碳","devvalue":"457","devunit":"ppm","devtime":"2023-06-02 16:18:54"},{"channelid":5,"devname":"土壤温度","devvalue":"40.1","devunit":"℃","devtime":"2023-06-02 16:18:54"},{"channelid":6,"devname":"土壤湿度","devvalue":"25.1","devunit":"%","devtime":"2023-06-02 16:18:54"},{"channelid":7,"devname":"土壤电导率","devvalue":"200","devunit":"μS/cm","devtime":"2023-06-02 16:18:54"},{"channelid":8,"devname":"土壤pH值","devvalue":"6.8","devunit":"pH","devtime":"2023-06-02 16:18:54"},{"channelid":9,"devname":"土壤氮含量","devvalue":"15","devunit":"mg/Kg","devtime":"2023-06-02 16:18:54"},{"channelid":10,"devname":"土壤磷含量","devvalue":"21","devunit":"mg/Kg","devtime":"2023-06-02 16:18:54"},{"channelid":11,"devname":"土壤钾含量","devvalue":"53","devunit":"mg/Kg","devtime":"2023-06-02 16:18:54"}]}
根据上面的请求参数和请求结果,你可以定义一个实体类`ResultEntity`来接收返回结果:
```java
public class ResultEntity {
private Integer code;
private String deviceid;
private List<DataEntity> data;
// getters and setters
}
public class DataEntity {
private Integer channelid;
private String devname;
private String devvalue;
private String devunit;
private String devtime;
// getters and setters
}
```
然后使用RestTemplate发送POST请求并接收结果:
```java
RestTemplate restTemplate = new RestTemplate();
String url = "http://www.ousuiot.com:9801/querypubdata";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
Map<String, String> requestMap = new HashMap<>();
requestMap.put("signature", "FC73D944C6E54087ABDC3F71AD7857BF");
requestMap.put("deviceid", "230417100002");
HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(requestMap, headers);
ResponseEntity<ResultEntity> responseEntity = restTemplate.postForEntity(url, requestEntity, ResultEntity.class);
ResultEntity result = responseEntity.getBody();
```
这样,`result`对象就包含了返回结果中的所有信息。可以通过`result.getCode()`获取返回的状态码,通过`result.getData()`获取设备数据列表。需要注意的是,`ResultEntity`中的属性名要与返回结果中的字段名一致。
阅读全文