11

JSON を機能させるのに問題があります。ObjectMapper解決できません。ライブラリは正しくインポートされます。

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONException;
import net.sf.json.util.*;

import com.fasterxml.jackson.*;

public class Json {
    private static final String jsonFilePath = "C:\\Users\\Juergen\\Desktop\\filesForExamples\\mapExample.json";

    public static void objectToJSON(HashMap<String, Mat> map) {
        //Map<String, Object> mapObject = new HashMap<String, Object>();
        ObjectMapper mapper = new ObjectMapper();

        try {
            objectMapper.writeValue(new File(jsonFilePath), map);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
4

2 に答える 2

12
If you are using **maven** project then add the following in the `POM.xml`

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>2.12.1</version>
</dependency>
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.12.1</version>
</dependency>
    
But if you are using a **simple java** project then you need to add the following jars in your class path:
    
    jackson-core-2.1.X,
    jackson-databind-2.1.X
于 2017-01-06T07:53:53.607 に答える