首页 \ 问答 \ 在Java中动态修改未知JSON的JsonNode(Modify JsonNode of unknown JSON dynamically in Java)

在Java中动态修改未知JSON的JsonNode(Modify JsonNode of unknown JSON dynamically in Java)

我试图修改一个JSON(未知结构),其中JsonPath及其等效的XML Xpath是我所知道的。

我已经厌倦了使用com.jayway.jsonpath.JsonPath库。 JsonPath的问题是,它返回值但我无法修改目标节点。

以下是我的代码片段

JsonPath.read(jsonFile, jsonPath);
JsonPath.parse(jsonPath);
System.out.println("Author: "+JsonPath.read(jsonFile, jsonPath));

我尝试使用杰克逊,如前面提到的排队中提到的,但它需要逐个节点遍历,如下所示

((ObjectNode) parent).put(fieldName, newValue);

由于结构未知,我无法做到这一点。

我已经尝试了递归解析JSON对象的问题的答案,但它说如何解析不修改

我需要做以下几点

JsonNode root = mapper.readTree("Json in form of String");
((JsonNode)(root.get("JsonPath")).set("New Value");

有什么办法可以实现这一目标吗?


I am trying to modify a JSON (of an unknown structure) where the JsonPath and its equivalent XML Xpath is known to me.

I have tired using com.jayway.jsonpath.JsonPath library for the same. The problem with JsonPath is, it returns me the value but I am not able to modify the Target Node.

Follows is my code snippet for the same

JsonPath.read(jsonFile, jsonPath);
JsonPath.parse(jsonPath);
System.out.println("Author: "+JsonPath.read(jsonFile, jsonPath));

I tried using Jackson as mentioned in previously asked quetion, But it needs to be traversed node by node as follows

((ObjectNode) parent).put(fieldName, newValue);

which I cannot do due to unknown structure.

I have tried the answer given to the question recursively parse JSON object but it says how to parse not modify

I need to do the follows

JsonNode root = mapper.readTree("Json in form of String");
((JsonNode)(root.get("JsonPath")).set("New Value");

Is there any way in which this can be achieved?


原文:https://stackoverflow.com/questions/41360172
更新时间:2023-07-16 22:07

最满意答案

这适用于chrome和firefox中的4个

@font-face {
    font-family: 'myFnt';
    src: url('webfonts/name.ttf');
    font-weight: normal;
    font-style: normal;
}

你在使用.htaccess文件吗? 如果是,请将.ae放在.htaccess文件中

<FilesMatch "\.(ttf|otf|eot)$">
    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    </IfModule>
</FilesMatch>

在这里你可以阅读解决方案font-face不仅仅工作firefox


this works for 4 in chrome and firefox as well

@font-face {
    font-family: 'myFnt';
    src: url('webfonts/name.ttf');
    font-weight: normal;
    font-style: normal;
}

are you using a .htaccess file? If yes put theae on your .htaccess file

<FilesMatch "\.(ttf|otf|eot)$">
    <IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin "*"
    </IfModule>
</FilesMatch>

here you can read the solution font-face not working only firefox

相关问答

更多
  • 尝试创建嵌入的字体对象并使用此字体呈现文本: //this code should run once at initialization/application startup FontFactory.register("resources/wingding_font.ttf"); Font textFont = FontFactory.getFont("wingding", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10); //10 is the size ...
  • 出于隐私原因,图像必须完全独立,即一个文件中的所有内容。 如果您希望在将SVG用作图像时(在图像标记中或作为CSS图像背景)中使用ttf字体,则必须对其进行base64编码并将其作为数据URL嵌入到图像中。 @font-face { font-family: 'LHF'; src: url("data:application/x-font-ttf;base64,[base-encoded font here]"); } 或者,您可以使用