我有一个包含 70 个对象的 JSON 文件,每个对象都包含数组等元素。以下是 JSON 对象的示例:
{
"journal": ".....",
"category": ["Sport", "football", "Real Madrid"],
"abstract": "Here is an example"
}
首先,我使用元素“category”
的字符串创建文件夹。下一步是根据元素 "abstract"
的字符串创建一个 .txt
文件。我要做的是将每个 .txt
文件保存在这些文件夹中。
例如,元素 "abstract"
包含字符串“Here is an example”,我使用此短语创建一个 .txt
文件,我想知道如何做我将其保存在文件夹 Sport
、Football
和 Real Madrid
中。
最佳答案
这是一些 java 示例:
// create a list of folder names and call it "folderArray".
// You are already doing something like this, but I don't know the variable name.
// You also have the name of the abstract text file name in a variable.
// This code assumes that variable is called "abstractFileName".
for (final String folder : folderArray)
{
final String newFileName = folder + File.separatorChar + abstractFileName;
// create a file with the name "newFileName"
// Write the abstract contents to the new file.
}
关于java - 如何在多个文件夹中保存字符串 JSON 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36265926/