Json 데이터에서 원하는 데이터를 가져와서 편집하고 싶습니다

한국 공휴일 정보를 가져오고 싶습니다.
최종 목표는 정보를 가져와서 Dictionary key, value로 “어린이날”, "20230505"처럼 넣어서
반환하는 것이 목표입니다.

data.go.kr에서 공휴일 정보(특일정보)를 HTTP REQUEST로 가져오도록 구현을 했고요,
response를 찍어보면 아래와 같이 나옵니다.

“{"response":{"header":{"resultCode":"00","resultMsg":"NORMAL SERVICE."},"body":{"items":{"item":[{"dateKind":"01","dateName":"어린이날","isHoliday":"Y","locdate":20230505,"seq":1},{"dateKind":"01","dateName":"부처님오신날","isHoliday":"Y","locdate":20230527,"seq":1}]},"numOfRows":10,"pageNo":1,"totalCount":2}}}”

이걸 Deseialize JSON을 통해서 아래까지는 만들었습니다.
“response”: {
“header”: {
“resultCode”: “00”,
“resultMsg”: “NORMAL SERVICE.”
“body”: {
“items”: {
“item”: [
“dateKind”: “01”,
“dateName”: “어린이날”,
“isHoliday”: “Y”,
“locdate”: 20230505,
“seq”: 1
“dateKind”: “01”,
“dateName”: “부처님오신날”,
“isHoliday”: “Y”,
“locdate”: 20230527,
“seq”: 1
“numOfRows”: 10,
“pageNo”: 1,
“totalCount”: 2

여기서가 잘 안되는데, input으로는 연도와 월을 넣어주어야 하고요,
그럼 그 해의 그 월에 대한 response가 위와 같이 나오거든요.
위 형태에서 어떻게 구현을 하면 입력 데이터가 매번 달라지더라도,
Dictionary(dateName, locdate) 형태 로 출력을 만들 수 있을까요?
조언을 요청드립니다 ~


Yes you can deserialize the jaon and then use as below

Create and initialize a dictionary dict = new dictionary(Of string,string)

  1. For loop on Ctype(jobj("response")("items")("item"),Jarray) and change type argument to jobject in the for loop properties
  2. Inside loop use assign dict(currentitem("dateName").ToString) = currentitem("locdate").ToString

Hope this helps


Thanks for your help.
I tried following your advice, but I still get an error in For each.
The error message is this.

→ Log Message: Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object. at lambda_method(Closure , ActivityContext )
at Microsoft.VisualBasic.Activities.VisualBasicValue1.Execute(CodeActivityContext context) at System.Activities.CodeActivity1.InternalExecuteInResolutionContext(CodeActivityContext context)
at System.Activities.Runtime.ActivityExecutor.ExecuteInResolutionContext[T](ActivityInstance parentInstance, Activity1 expressionActivity) at System.Activities.InArgument1.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance activityInstance, ActivityExecutor executor)
at System.Activities.RuntimeArgument.TryPopulateValue(LocationEnvironment targetEnvironment, ActivityInstance targetActivityInstance, ActivityExecutor executor, Object argumentValueOverride, Location resultLocation, Boolean skipFastPath)
at System.Activities.ActivityInstance.InternalTryPopulateArgumentValueOrScheduleExpression(RuntimeArgument argument, Int32 nextArgumentIndex, ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Boolean isDynamicUpdate) at System.Activities.ActivityInstance.ResolveArguments(ActivityExecutor executor, IDictionary2 argumentValueOverrides, Location resultLocation, Int32 startIndex)
at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

I attach my file. Could I get some additional help?

공휴일정보가져오기.xaml (15.3 KB)