我正在安装NewtonSoft.Json来解析.Net应用程序中的Json.当我使用VS 2012时,它无法通过NuGet安装.这是我得到的错误:
'Newtonsoft.Json' already has a dependency defined for 'Microsoft.CSharp'
Run Code Online (Sandbox Code Playgroud)
我试图复制dll并使用它,似乎在这个版本(10.0.2)中搞砸了一些依赖.
经过几个小时的研究,最后我发现它是VS2012和Newtonsoft Json 10.0.2的兼容性问题.
JsonParser为 Spring Boot 应用程序获取已弃用的消息,
JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
Run Code Online (Sandbox Code Playgroud)
什么是替代方案?
我创建了一个方法,如在线所示:
@NonCPS
def parseJsonString(String jsonString) {
def lazyMap = new JsonSlurper().parseText(jsonString)
// JsonSlurper returns a non-serializable LazyMap, so copy it into a regular map before returning
def m = [:]
m.putAll(lazyMap)
return m
}
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
错误:java.io.NotSerializableException:groovy.json.internal.LazyMap
为了解决这个问题,我必须创建一个完整的方法来执行整个步骤。例如,在一个方法中,我会做与上面相同的操作,解析我想要的信息,最后将其作为字符串返回。
然而,这带来了另一个问题,尤其是如果您将此方法包装在 a 中withCredentials,则需要另一个withCredentials.
我需要在嵌入式系统上解析一个小的JSON文件(只有10K RAM /闪存).JSON是:
{
"data1":[1,2,3,4,5,6,7,8,9],
"data2":[
[3,4,5,6,1],
[8,4,5,6,1],
[10,4,5,3,61],
[3,4,5,6,1],
[3,4,5,6,1],
[3,4,5,6,1]
]}
Run Code Online (Sandbox Code Playgroud)
jsmn看起来很符合要求,但它不像大多数JSON解析器,因为它只给你令牌.我试过了,但无法理解.
有人可以分享一个如何用jsmn解析它的例子吗?
我正在尝试将 xml 解析为多个不同的文件 -
示例 XML
<integration-outbound:IntegrationEntity
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<integrationEntityHeader>
<integrationTrackingNumber>281#963-4c1d-9d26-877ba40a4b4b#1583507840354</integrationTrackingNumber>
<referenceCodeForEntity>25428</referenceCodeForEntity>
<attachments>
<attachment>
<id>d6esd1d518b06019e01</id>
<name>durance.pdf</name>
<size>0</size>
</attachment>
<attachment>
<id>182e60164ddd4236b5bd96109</id>
<name>ssds</name>
<size>0</size>
</attachment>
</attachments>
<source>SIM</source>
<entity>SUPPLIER</entity>
<action>CREATE</action>
<timestampUTC>20200306T151721</timestampUTC>
<zDocBaseVersion>2.0</zDocBaseVersion>
<zDocCustomVersion>0</zDocCustomVersion>
</integrationEntityHeader>
<integrationEntityDetails>
<supplier>
<requestId>2614352</requestId>
<controlBlock>
<dataProcessingInfo>
<key>MODE</key>
<value>Onboarding</value>
</dataProcessingInfo>
<dataProcessingInfo>
<key>Supplier_Type</key>
<value>Operational</value>
</dataProcessingInfo>
</controlBlock>
<id>1647059</id>
<facilityCode>0001</facilityCode>
<systemCode>1</systemCode>
<supplierType>Operational</supplierType>
<systemFacilityDetails>
<systemFacilityDetail>
<facilityCode>0001</facilityCode>
<systemCode>1</systemCode>
<FacilityStatus>ACTIVE</FacilityStatus>
</systemFacilityDetail>
</systemFacilityDetails>
<status>ACTIVE</status>
<companyDetails>
<displayGSID>254232128</displayGSID>
<legalCompanyName>asdasdsads</legalCompanyName>
<dunsNumber>03-175-2493</dunsNumber>
<legalStructure>1</legalStructure>
<website>www.aaadistributor.com</website>
<noEmp>25</noEmp>
<companyIndicator1099>No</companyIndicator1099>
<taxidAndWxformRequired>NO</taxidAndWxformRequired>
<taxidFormat>Fed. Tax</taxidFormat>
<wxForm>182e601649ade4c38cd4236b5bd96109</wxForm>
<taxid>27-2204474</taxid>
<companyTypeFix>SUPPLIER</companyTypeFix>
<fields>
<field>
<id>LOW_CUURENT_SERV</id>
<value>1</value>
</field>
<field>
<id>LOW_COI</id>
<value>USA</value>
</field>
<field>
<id>LOW_STATE_INCO</id> …Run Code Online (Sandbox Code Playgroud) 杰森:
{
"im:rating": {
"label": "1"
}
}
Run Code Online (Sandbox Code Playgroud)
在尝试在 groovy 中使用 Jsonpath 时如果我使用这个'$.im: rating'
它显示以下错误
Run Code Online (Sandbox Code Playgroud)Caused by: com.nebhale.jsonpath.InvalidJsonPathExpressionException: Illegal字符 'PathCharacter [类型 = [],值 =:,位置 = 4]' $.im:评级 ----^ 非法字符 'PathCharacter [类型 = [SIMPLE_NAME_CHARACTER,LETTER,COMPLEX_NAME_CHARACTER],值 = r,位置 = 5 ]' $.im: rating -----^ 非法字符 'PathCharacter [types=[SIMPLE_NAME_CHARACTER, LETTER, COMPLEX_NAME_CHARACTER], value=a,position=6]' $.im: rating ------^ 非法字符 'PathCharacter [types=[SIMPLE_NAME_CHARACTER, LETTER, COMPLEX_NAME_CHARACTER], value=t,position=7]' $.im: rating -------^ 非法字符 'PathCharacter [types=[SIMPLE_NAME_CHARACTER, LETTER, COMPLEX_NAME_CHARACTER] ,值=i,位置=8]'$.im:评级--------^非法字符'PathCharacter [类型=[SIMPLE_NAME_CHARACTER,LETTER,COMPLEX_NAME_CHARACTER],值=n,位置=9]'$。 im:评级 ---------^ 非法字符 'PathCharacter [类型=[SIMPLE_NAME_CHARACTER,LETTER,COMPLEX_NAME_CHARACTER],值=g,位置=10]' $.im:评级 -------- --^
Run Code Online (Sandbox Code Playgroud)at com.nebhale.jsonpath.JsonPath.compile(JsonPath.java:85) at com.nebhale.jsonpath.JsonPath.read(JsonPath.java:182)
我正在尝试使用 Moshi 解析 Json 响应,我遇到的问题是键的值是字符串上的 Json 包装:
{"mobile_accounts_account_showProperties":"[{\"name\": \"current\"},{\"name\": \"available\"}]"}
Run Code Online (Sandbox Code Playgroud)
这是我的课
@Json(name = "mobile_accounts_account_showProperties")
private List<PropertyConfig> showProperties;
Run Code Online (Sandbox Code Playgroud)
我尝试在解析之前用 areplace("\"[", "[")和 a删除 ("")replace("\\", "")但不是一个选项,因为这删除了我确实需要的一些其他引号。我尝试使用 JsonAdapter 但我无法做到这一点。JsonAdapter 没有接到电话。
public class PropertyConfigJsonAdapter {
public PropertyConfigJsonAdapter() {
}
@ToJson
String toJson(List<PropertyConfig> card) {
return "";
}
@FromJson
List<PropertyConfig> fromJson(String object) {
return new ArrayList<>();
}
Run Code Online (Sandbox Code Playgroud)
我尝试这样做以查看 JsonAdapter 是否正在调用,但它从未调用过“fromJson”方法。这是我调用适配器的方式:
MoshiConverterFactory.create(new Moshi.Builder().add(new PropertyConfigJsonAdapter()).build())
Run Code Online (Sandbox Code Playgroud) 我有一个简单的控制器(代码)
@RestController
@RequestMapping("/profiles" , produces = [MediaType.APPLICATION_JSON_VALUE])
class Controller(@Autowired val restClient: RestClient) {
@GetMapping("/simple-get")
fun simpleGetCall(): List<Profile> {
restClient.callClientGet()
return listOf(
Profile("firstname1", "lastname1"),
Profile("firstname2", "lastname2"))
}
}
Run Code Online (Sandbox Code Playgroud)
控制器正在调用 RestClient 进行客户端调用(代码)
@Service
class RestClient(@Autowired val restTemplate: RestTemplate) {
fun callClientGet(){
try {
restTemplate.getForEntity(
"/profiles/simple-get",
Number::class.java
)
}catch(exception: Exception){
throw MyClientCallException("this is an exception")
}
}
}
Run Code Online (Sandbox Code Playgroud)
MyClientCallException 看起来像这样(代码)
class MyClientCallException(message: String) :
ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message)
Run Code Online (Sandbox Code Playgroud)
我的班级中有 3 个功能测试(代码)我使用org.springframework.test.web.client.MockRestServiceServer作为服务器
@Test
fun `when calling …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 JSON 输入解析为 Python 中的字符串,但无法解析为列表或字典,因为 JSON 输入的格式不正确(由于中间件的限制,这里不能做太多事情。)
{
"Records": "{Output=[{_fields=[{Entity=ABC , No=12345, LineNo= 1, EffDate=20200630}, {Entity=ABC , No=567, LineNo= 1, EffDate=20200630}]}"
}
Run Code Online (Sandbox Code Playgroud)
我试过json.loads过ast.literal(无效语法错误)。
我怎样才能加载这个?
我正在尝试向服务器发送 POST 请求,获取响应并解析它(它是一个 JSON 文件)。
我使用 Unirest 来处理我的 POST 请求,如下所示:
HttpResponse<JsonNode> response = Unirest
.post("http://myserver.com/file")
.header("cache-control", "no-cache")
.header("Postman-Token", "02ec2fa1-afdf-4a2a-a535-353424d99400")
.header("Content-Type", "application/json")
.body("{some JSON body}")
.asJson();
// retrieve the parsed JSONObject from the response
JSONObject myObj = response.getBody().getObject();
// extract fields from the object
String msg = myObj.toString();
System.out.println(msg);
Run Code Online (Sandbox Code Playgroud)
但我在获取原始 JSON 文本时遇到问题(我想用它JSONPath来解析响应)。
我怎样才能做到这一点?toString()到目前为止,我所有调用方法的尝试都失败了。