标签: jsonparser

如何使用改造来解析动态按键响应

我在使用改造电话进行解析时遇到问题。这个不重复的问题。我尝试了很多谷歌搜索,也尝试了许多解决方案,但在我的情况下不起作用。因此,请不要对此问题投反对票。

我也制作了pojo类,但是没有绑定方法。数据

public class Data {
    @SerializedName("id")
    @Expose
    private Integer id;
    @SerializedName("name")
    @Expose
    private String name;
    @SerializedName("symbol")
    @Expose
    private String symbol;
    @SerializedName("website_slug")
    @Expose
    private String websiteSlug;
    @SerializedName("rank")
    @Expose
    private Integer rank;
    @SerializedName("circulating_supply")
    @Expose
    private Double circulatingSupply;
    @SerializedName("total_supply")
    @Expose
    private Double totalSupply;
    @SerializedName("max_supply")
    @Expose
    private Double maxSupply;
    @SerializedName("quotes")
    @Expose
    private Quotes quotes;
    @SerializedName("last_updated")
    @Expose
    private Integer lastUpdated;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public …
Run Code Online (Sandbox Code Playgroud)

android retrofit2 jsonparser

1
推荐指数
1
解决办法
378
查看次数

意外字符('='(代码 61)):解析 JsonString 时

解析 JSONString ( assigned=[util.TaskAudit@24c7b944]}) 时如下:

Map<String, List<TaskAudit>> auditTrailMap = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();
mapper.configure(Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);

try {
    auditTrailMap = mapper.readValue(strObject, new TypeReference<Map<String, List<TaskAudit>>>(){});
} catch (IOException e) {
    log.error("{}", e);
}
Run Code Online (Sandbox Code Playgroud)

我收到以下异常:

com.fasterxml.jackson.core.JsonParseException:意外的字符('='(代码61)):期望用冒号分隔字段名称和值[junit],位于[来源:{assigned=[util.TaskAudit@24c7b944]} ; 行:1,列:11]

任何人都可以提供有关如何解决该问题的任何线索。

编辑:基本上这个函数的输入是来自数据库的字符串字段。保存时我们这样保存:

        Map<String, List<TaskAudit>> auditTrailMap = new HashMap<>();
        auditTrailMap.put("assigned", taskAuditList);
        String jsonString =  new JSONObject(auditTrailMap).toString();
Run Code Online (Sandbox Code Playgroud)

但是,在尝试解析 jsonString 时,它就像 (signed=[util.TaskAudit@24c7b944]}) 一样,我不知道“=”来自哪里以及如何解析它。

java jackson java-8 jsonparser

1
推荐指数
1
解决办法
1万
查看次数

如何解决 MismatchedInputException: Cannot Construction instance of `java.util.HashSet` 异常

在我的程序中,我尝试更新用户的电子邮件。但这给了我一个例外说

嵌套异常是 com.fasterxml.jackson.databind.exc.MismatchedInputException:无法构造实例java.util.HashSet

但是,当我通过添加技能和电子邮件更新用户时,它并没有给我这个例外。

我尝试创建一个默认构造函数,但它不起作用。我也尝试使用 Json Creator。它对我也不起作用。我可以看到问题是当我将技能集清空时,此异常正在上升。但我没有一个明确的想法,如何克服这个情况。

这是我的员工实体

@Entity
@Table(name = "Employee")
public class Employee implements Serializable{

    private static final long serialVersionUID = -3009157732242241606L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private long emp_id;

    @Column(name = "emp_fname")
    private String emp_fname;

    @Column(name = "emp_lname")
    private String emp_lname;

    @Column(name = "emp_email")
    private String emp_email;

    @Column(name = "emp_dob")
    private Date emp_dob;

    @ManyToMany(cascade = CascadeType.MERGE)
    @JoinTable(name = "emp_skills",
            joinColumns = @JoinColumn(name = "emp_id", referencedColumnName = "emp_id"),
            inverseJoinColumns = @JoinColumn(name = "s_id",referencedColumnName = "s_id"))
    private Set<Skills> skills; …
Run Code Online (Sandbox Code Playgroud)

json json-deserialization spring-boot jsonparser

1
推荐指数
1
解决办法
5264
查看次数

使用Decodable返回的空模型解析JSON

我正在尝试加载本地JSON文件并使用符合Decodable协议的模型进行解析。

JSON文件:

[
{
    "body": {},
    "header": {
        "returnCode": "200",
        "returnMessage": "Successfully Received",
    }
}
]
Run Code Online (Sandbox Code Playgroud)

响应消息模型:

struct ResponseMessage: Decodable {

    struct header: Decodable {
        let returnCode: String
        let returnMessage: String
    }
}
Run Code Online (Sandbox Code Playgroud)

模拟API的实现:

let url = Bundle.main.url(forResource: "MockJSONData", withExtension: "json")!
            do {
                let data = try Data(contentsOf: url)
                let teams = try JSONDecoder().decode(ResponseMessage.self, from: data)
                print(teams)
            } catch {
                print(error)
            }
Run Code Online (Sandbox Code Playgroud)

但是响应消息为此返回空数据。

感谢您的帮助和建议!

谢谢

xcode ios swift jsonparser jsondecoder

1
推荐指数
1
解决办法
64
查看次数

使用特殊字符\"在Javascript中提取JSON值

我如何从下面的 json 中提取文本,因为它包含 \" 它给了我一个未定义的

{ 
   "answers":[ 
      { 
         "questions":[  ],
         "answer":"{\"text\":\"I am Ellina. I can't believe you forgot my name\",\"speech\":\"I am Ellina. I can't believe you forgot my name\"}",
         "score":100,
         "id":106,
         "source":"Editorial",
         "metadata":[ 

         ],
         "context":{ 
            "isContextOnly":false,
            "prompts":[ 

            ]
         }
      }
   ],
   "debugInfo":null,
   "activeLearningEnabled":false
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用 console.log( Answer: ${JSON.stringify(res.data.answers[0].answer.text)}); 还有console.log( Answer: ${res.data.answers[0].answer.text});

javascript json node.js jsonparser

1
推荐指数
1
解决办法
52
查看次数

如何在不更改 Google Apps 脚本的情况下进行 Json 解析

我在 Apps Script 中请求 Go to Webinar API,响应如下:

{"joinUrl":"https://example.com","asset":true,"registrantKey":3669516009270899211,"status":"APPROVED"}
Run Code Online (Sandbox Code Playgroud)

当我制作 JSON.parse 时,我得到如下信息:

{joinUrl=https://example.com, asset=true, registrantKey=3.6695160092708992E18, status=APPROVED}
Run Code Online (Sandbox Code Playgroud)

RegistrantKey 变了,不知道为什么。

那是我的代码:

      try{
    var resp =  UrlFetchApp.fetch(url,options)
    var json=JSON.parse(resp);
    return json
  }catch(err){
    Logger.log(err);
    return err;
Run Code Online (Sandbox Code Playgroud)

}

json request google-apps-script jsonparser

1
推荐指数
1
解决办法
209
查看次数

无法解析键值名称周围带有单引号的字符串数组

我正在尝试将数组解析为 JSON.parse,其中键和值周围有单引号。但它抛出以下错误。

Uncaught SyntaxError: Unexpected token ' in JSON at position 1

我传递的数组是:

["{'name': 'Jhon'}"]

不知何故,这个字符串没有抛出任何错误。

['{"name": "Jhon"}']

任何帮助将不胜感激。提前致谢。

javascript parsing json angularjs jsonparser

1
推荐指数
1
解决办法
148
查看次数

如何在 JavaScript 中将带有等号“=”的字符串转换为 json

以下字符串从 Kafka 返回到 Lambda 连接器。

'{device_id=D_2021_A07, key=tele_metrics, sensor_1=62, sensor_2=23}'
Run Code Online (Sandbox Code Playgroud)

我想将其转换为有效的 JSON,如下所示

{
    "device_id": "D_2021_A07",   //String
    "key": "tele_metrics",       //String
    "sensor_1": 62,              //Integer
    "sensor_2": 23               //Integer
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能在 JavaScript 中做到这一点。

lambda apache-kafka jsonparser

1
推荐指数
1
解决办法
2617
查看次数

在Swift 4中使用codable解析嵌套数组

我收到许多随机问题。大多像某些结构无法解码,无法理解如何定义结构。

请发现代码被截断

var JSON = """
{"variants":{"variant_groups":[{"group_id":"1","name":"Crust","variations":[{"name":"Thin","price":0,"default":1,"id":"1","inStock":1},{"name":"Thick","price":0,"default":0,"id":"2","inStock":1,"isVeg":1},{"name":"Cheese burst","price":100,"default":0,"id":"3","inStock":1,"isVeg":1}]},{"group_id":"2","name":"Size","variations":[{"name":"Small","price":0,"default":1,"id":"10","inStock":1,"isVeg":0},{"name":"Medium","price":100,"default":0,"id":"11","inStock":1,"isVeg":1},{"name":":Large","price":200,"default":0,"id":"12","inStock":1,"isVeg":0}]},{"group_id":"3","name":"Sauce","variations":[{"name":"Manchurian","price":20,"default":0,"id":"20","inStock":1,"isVeg":0},{"name":"Tomato","price":20,"default":0,"id":"21","inStock":1,"isVeg":1},{"name":"Mustard","price":20,"default":0,"id":"22","inStock":1,"isVeg":0}]}],"exclude_list":[[{"group_id":"1","variation_id":"3"},{"group_id":"2","variation_id":"10"}],[{"group_id":"2","variation_id":"10"},{"group_id":"3","variation_id":"22"}]]}}
""".data(using: .utf8)

/* 
 not sure is this the right way to define Root
*/
    struct Root : Codable {

        let variants : varientStruct
        let exclude_list : exclude_list

    }

    struct exclude_list : Codable{
        let variation_id : String
        let group_id : String
    }

    struct varientStruct: Codable {
        let variant_groups = [variant_groups_struct]
    }
    struct variant_groups_struct : Codable {
        let group_id : String
        let name :String
        let variations: [variationsStruct]
    }

    struct variationsStruct :Codable {
        let name …
Run Code Online (Sandbox Code Playgroud)

ios swift4 xcode9 codable jsonparser

0
推荐指数
1
解决办法
1724
查看次数

使用 nlohmann json 解析 JSON

我正在尝试使用 nlohmann 的 json.hpp 解析 JSON 结构。但我不会从字符串创建 JSON 结构。我已经尝试了所有方法,但仍然失败。

我的要求是:

1) 从字符串创建 JSON 结构。

2)从中找到“statusCode”的值。

经过这么长时间的尝试,我真的很怀疑,nlohmann的json解析器是否支持嵌套JSON。

#include "json.hpp"
using namespace std;

int main(){

    // giving error 1
    nlohmann::json strjson = nlohmann::json::parse({"statusResp":{"statusCode":"S001","message":"Registration Success","snStatus":"Active","warrantyStart":"00000000","warrantyEnd":"00000000","companyBPID":"0002210887","siteBPID":"0002210888","contractStart":"00000000","contractEnd":"00000000"}});

    // Giving error 2:
   auto j= "{
    "statusResp": {
        "statusCode": "S001",
        "message": "Registration Success",
        "snStatus": "Active",
        "warrantyStart": "20170601",
        "warrantyEnd": "20270601",
        "companyBPID": "0002210887",
        "siteBPID": "0002210888",
        "contractStart": "00000000",
        "contractEnd": "00000000"
    }
   }"_json;

   // I actually want to get the value of "statusCode" code from the JSOn structure. But no idea …
Run Code Online (Sandbox Code Playgroud)

c++ json nlohmann-json jsonparser

0
推荐指数
1
解决办法
2万
查看次数

带空格的 Perl json 键

我如何解析键中有空格的 perl json 对象

{
   "abc" : [
       "lmn" : {
          "Ab Cd" : "Xy Zw",
          "Ef Gh" : "Pq Rs",
       }
   ]
}
Run Code Online (Sandbox Code Playgroud)

regex perl json jsonparser

0
推荐指数
1
解决办法
111
查看次数

使用JQ工具实用程序解析或查看JSON数据字段,其中字段名称的键名称中带有“-”破折号

我有一个JSON数据文件(如下所示),我正在尝试使用jq实用程序查找字段值。

除键名中包含-短划线字符的字段外,其他方法都可以正常工作。

如何获取(至少使用)下元素的“ field-2 ”,“ field-three 3 ”或“ field-three.url ”值?content.book1jq

我尝试了以下操作来获取值,但是对于键名中包含短划线的字段,它给了我以下错误-。我试图反斜杠-字符,但这也没有帮助。

发现错误类型:

jq: error (at <stdin>:27): null (null) and number (2) cannot be subtracted
jq: 1 compile error

jq: error: three/0 is not defined at <top-level>

jq: error: syntax error, unexpected INVALID_CHARACTER, expecting $end (Unix shell quoting issues?) at <top-level>

jq: error: syntax error, unexpected INVALID_CHARACTER, expecting FORMAT or QQSTRING_START (Unix shell quoting issues?) at <top-level>, line 1:
Run Code Online (Sandbox Code Playgroud)

命令:

$ …
Run Code Online (Sandbox Code Playgroud)

python json dictionary jq jsonparser

-1
推荐指数
1
解决办法
971
查看次数