Hello. I have a problem with parsing json in batch. Currently i'm using class RetailCommonWebAPI. I know where i have a mistake but don't have any idea how to fix this.
Thanks for help.
serviceUrl = this.getUrl();
request = RetailWebRequest::newUrl(serviceUrl);
response = webApi.getResponse(request);
responseStr = response.parmData();
map = RetailCommonWebAPI::getMapFromJsonString(responseStr);
mapEnumerator = map.getEnumerator();
My responseStr is str type and this is a mistake. How should i convert him to IConvertible or IDictionary type?
Look at what type is returned by response.parmData().
This is string type
If it's string, I don't understand why you said that assigning it to a string variable was a mistake.
You should focus on the exception instead. I assume you're getting a TargetInvocationException containing an InvalidCastException in its InnerException property. Look at StackTrace property of the inner exception to understand which code threw it.
I'm assuming that this is a mistake because i've got same error like on this topic:
I don't see anything in that thread that would claim that assigning a string to a string variable is a mistake.
The problem there was about constructing a hash table object.
I didn't wrote anywhere that i have a problem with assigning string to string...
I've got a problem with creating map from jsonString and now i don't know how to convert my variable - "responseStr" to type that's gonna be acceptable by this method (RetailCommonWebAPI::getMapFromJsonString)
You said that "My responseStr is str type and this is a mistake", but it's not. You get a string from parmData(), you put it to a string variable and then you pass it to a method expecting a string. Everything is all right; that responseStr is a string is NOT a mistake.
The other thread is about some issues in the implementation of getMapFromJsonString(); you can try to apply solutions offered there. Also make sure that your string has the right structure.
Trying to convert the string to IDictionary before calling getMapFromJsonString() makes little sense, because the method expects a string and not IDictionary. The discussion in the other thread was about changing the parameter type of getMap(), not sending IDictionary to getMapFromJsonString().