Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 创建DICOM属性时JSON的SAXParser_Java_Json_Xml_Parsing_Saxparser - Fatal编程技术网

Java 创建DICOM属性时JSON的SAXParser

Java 创建DICOM属性时JSON的SAXParser,java,json,xml,parsing,saxparser,Java,Json,Xml,Parsing,Saxparser,我目前正在处理一个项目,接收Dicom XML数据,使用SAXParser解析数据,将解析后的数据存储为Attributes对象(),并将Attributes对象添加到attributesList中 我用于XML的解析器是SAXParser,我还使用SAXParserFactory创建XML解析器实例 在更改了accept头之后,我现在收到的是JSON格式的相同DICOM数据,而不是XML格式的数据。是否有一个JSON解析器和解析器工厂可以用于相同的目的?如果是,我应该如何修改我的当前代码 我当

我目前正在处理一个项目,接收Dicom XML数据,使用SAXParser解析数据,将解析后的数据存储为Attributes对象(),并将Attributes对象添加到attributesList中

我用于XML的解析器是SAXParser,我还使用SAXParserFactory创建XML解析器实例

在更改了accept头之后,我现在收到的是JSON格式的相同DICOM数据,而不是XML格式的数据。是否有一个JSON解析器和解析器工厂可以用于相同的目的?如果是,我应该如何修改我的当前代码

我当前的解析代码:

    public void bodyPart(int i, MultipartInputStream partInputStream) throws IOException {
        try {
            partInputStream.readHeaderParams();
            SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
            Attributes dicomAttributes = new Attributes();
            parser.parse(new AttributesList.NonClosingInputSteam(partInputStream), new ContentHandlerAdapter(dicomAttributes));
            attributesList.add(dicomAttributes);
        }
        catch (ParserConfigurationException | SAXException e) {
            // This should never happen unless the server returns invalid content. Log and return.
            log.error("Error parsing!", e);
            e.printStackTrace();
        }
    }

     private static class NonClosingInputSteam extends FilterInputStream {

    /**
     * Creates a new NonClosingInputStream that wraps another input stream.
     *
     * @param in the input stream to be wrapped
     */
    NonClosingInputSteam(InputStream in) {
        super(in);
    }


    /**
     * Overrides the default implementation of the input stream's close() method. This implementation
     * does nothing.
     */
    @Override
    public void close() {
        // Do nothing
    }
}

谢谢

默认情况下没有,因此您必须为此编写自己的

但是看看说明书

基于DICOM的Json格式,您可以看到数据的写入方式

更进一步,您可以基于此进行解析,以确保您的解析符合规范