在javascript中访问Java Map的键值对

时间:2018-05-20 10:38:03

标签: javascript java dictionary

我在后端有一个IManProfileSearchParameters,它作为Map发送到前端javascript。我需要获取所有键值对并在UI中显示它。为此,我尝试过,

IManWorkspaceSearchParameters

但它不起作用。有没有办法在javascript中处理Java地图?

1 个答案:

答案 0 :(得分:2)

您可以尝试使用ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper;),

export const fetchData = () => {
    return async (dispatch, getState) => {
        const appState = getState();

        const { uid } = appState.appReducer;

        await dispatch(fetchRequested());

        try {
            const response = await LookupApiFactory().fetch({ uid });

            dispatch(fetchSucceeded(response));

            return response;
        } catch (error) {
            dispatch(fetchFailed());

            return error;
        }
    }
}

然后你可以创建jsonObject as,

  String jsString =  new ObjectMapper().writeValueAsString(Map<String,String>)