解析'参数'JSON Watson Visual Recognition时出错

时间:2018-03-06 08:58:03

标签: java ibm-cloud ibm-watson visual-recognition

通过Java调用Watson Visual Recognition API时出现以下错误。任何帮助将受到高度赞赏。

Hi after getting the data inside getItems binding the data to callback getData as follows

getItems(storyList) {
    var story_list = [];
    async.mapLimit(
        storyList,
        10,
        ((item, callback) =>{
            console.log(item);
            fetch(`https://hacker-news.firebaseio.com/v0/item/${item}.json`)
                .then(res => res.json())
                .then(data => {
                    story_list.push(data);
                    this.props.getData(story_list);
                });
        }),
            ((err) =>{
            if (err) {
                console.error(err.message);
            } else {
                this.props.getData(story_list);
            }
        })
    );
}

堆栈跟踪:

       VisualRecognition service = new VisualRecognition(VisualRecognition.VERSION_DATE_2016_05_20);
       service.setApiKey("api_key");

       InputStream imagesStream = new FileInputStream("C:\\fruitbowl.jpg");
       ClassifyOptions classifyOptions =
               new ClassifyOptions.Builder().imagesFile(imagesStream).imagesFilename("fruitbowl.jpg")
                       .parameters("{\"classifier_ids\": [\"fruits_1462128776\", + \"SatelliteModel_6242312846\"],\"threshold\": 0.6}")
                       .build();
       ClassifiedImages result = service.classify(classifyOptions).execute();
       System.out.println(result);

2 个答案:

答案 0 :(得分:2)

我认为问题是参数字符串中间的+。我认为应该是:

.parameters("{\"classifier_ids\": [\"fruits_1462128776\", \"SatelliteModel_6242312846\"],\"threshold\": 0.6}")
                   .build();

答案 1 :(得分:0)

错误消息是指classifier-ids,而您有classifier_ids,因此可能会导致简单的拼写错误。虽然示例中的文档也有classifier_ids - https://www.ibm.com/watson/developercloud/visual-recognition/api/v3/?java#classify_an_image