Java 응용 프로그램을 호출하는 클라이언트 응용 프로그램에 gSOAP (C 언어)을 사용하고 있습니다. 나는 json_call()
함수를 사용하고있다. 요청 구조체에 JSON 입력 데이터가 채워져 있고 응답 구조체에 Java 서비스의 JSON 출력 데이터가 채워져 있습니다. 두 JSON은 일반적으로 동일한 구조를 갖지만 더 많거나 적은 요소 또는 변경된 요소를 가질 수 있습니다.gSOAP : C에서 두 개의 value-struct (JSON-content 포함)를 비교하는 방법은 무엇입니까?
이제 내 과제는 어떤 요소가 요청과 다른지 찾아 보는 것입니다.
{
"objects": [
{
"@id": "OBJ00001",
"name": "value",
...
},
{
"@id": "OBJ00002",
"number": 123,
...
},
...
]
}
내가 @id
필드와 같은 종류의 물체를 식별 할 수 있습니다 주요 요소는 같은 회원의 많은 대형 배열입니다.
for(i = 0; i < has_size(value_at(response, "objects")); i++)
그러나 다음 요청에 응답하여 동일한 @id
와 부재 ("사물")을 비교할 수있는 기능을 I'missing :
같은 것을하여 objects
배열을 반복하는 단순한 키우면. (모두가 존재하지 않는 !) "동일한"다음 "findMemberWithSameField"와 같은 뭔가 :
struct member *currentMemberInResponse = NULL;
struct member *memberWithSameField = NULL;
for(i = 0; i < has_size(value_at(response, "objects")); i++)
{
/* get the current member out of the response array */
currentMemberInResponse = nth_value(value_at(response, "objects"), i);
/* Find member/object with same @id in request */
memberWithSameField = findMemberWithSameField(value_at(request, "objects"), currentMemberInResponse , "@id"));
/* equal is true if all fields are the same */
if(equal(currentMemberInResponse, memberWithSameField))
{
/* Do nothing, because nothing changed */
}
else
{
/* Do something */
}
}
해당 작업에 어떤 생각? 그렇지 않으면 내 자신의 "findMemberWithSameField"및 "euqal"을 써야합니다.
종류는 JSON C++ API는 재귀 적으로 두 개체를 비교하는 operator==
을 정의 다니엘
https://github.com/DaveGamble/cJSON에서 jSON 패치를 지원합니다. –