我有以下angularJS代码来解析.js文件中的JSON:
$scope.updateAssociations = function() {
$scope.productModel = angular.toJson($rootScope.relationShipModel);
alert($scope.productModel);
var requestObj = { "channelCode": $rootScope.userSelectedChannel,
"modelTypeName" : $rootScope.selectedHierarchy.hier_name,
"relationShips" : $scope.productModel,
"associations" : $scope.selection,
"relID" : $routeParams.relID,
"prdCmptId" : $routeParams.prdCmpntId,
"associationsModelTypeName" : $rootScope.associationsModelTypeName
};
var result = $http.post('updateAssociations.do', requestObj);
result.success( function(response)
{
}
});
我没有得到" relationShips" Java类中的值:
ObjectMapper mapper=new ObjectMapper();
JsonNode node = mapper.readTree(requestBody);
RelationshipType relations = mapper.readValue(node.get("relationShips"), RelationshipType.class);
当代码尝试从mapper中检索值时,我得到以下异常:
org.codehaus.jackson.map.JsonMappingException: Can not instantiate value of type [simple type, class com.cpc.as.bean.RelationshipType] from JSON String; no single-String constructor/factory method.
我的关系JSON是:
[
{
"chnl_code":"BMG Catalog",
"rel_id":"59",
"rel_type_name":"product collateral assignment",
"entity_type_name":"generic feature",
"entity_role":"parent",
"related_to_entity":"collateral",
"related_to_crdnlty":"m",
"related_to_role":"child",
"dsply_name":"Collateral",
"hier_flag":null,
"related_to_object_type":"product",
"sub_role":null,
"atrbt_ind":"n",
"dpndnt_flag":"n",
"rel_ind":"n",
"dsply_model_type_name":null,
"sub_dsply_name":null,
"gen_new_flag":"y",
"allowDefaultSearchFlag":false,
"custom_price_type":null,
"rls_type":null,
"gradeMatrixRelated":false,
"releaseDriven":false
},
{
"chnl_code":"BMG Catalog",
"rel_id":"55",
"rel_type_name":"feature family assignment",
"entity_type_name":"generic feature",
"entity_role":"parent",
"related_to_entity":"feature family",
"related_to_crdnlty":"m",
"related_to_role":"child",
"dsply_name":"Feature Family",
"hier_flag":null,
"related_to_object_type":"group",
"sub_role":null,
"atrbt_ind":"n",
"dpndnt_flag":null,
"rel_ind":"n",
"dsply_model_type_name":null,
"sub_dsply_name":null,
"gen_new_flag":"y",
"allowDefaultSearchFlag":false,
"custom_price_type":null,
"rls_type":null,
"gradeMatrixRelated":false,
"releaseDriven":false
}
]
有人可以帮助我的代码中出现问题。提前谢谢。