का उपयोग करके फ़ाइल करने के लिए जेसन ऐरे को कैसे लिखें, मैंने एक जेसन फ़ाइल बनाई जहां मैं लिखने वाले जावा ऑब्जेक्ट को ऐरे तत्व के रूप में लिखना चाहता था। मैं जैक्सन का उपयोग कर रहा हूँ।जैक्सन
try{
String json;
String phyPath = request.getSession().getServletContext().getRealPath("/");
String filepath = phyPath + "resources/" + "data.json";
File file = new File(filepath);
if (!file.exists()) {
System.out.println("pai nai");
file.createNewFile();
}
json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(story);
Files.write(new File(filepath).toPath(), Arrays.asList(json), StandardOpenOption.APPEND);
}
यह नहीं है क्या मैं वास्तव में मैं सिर्फ Json की एक सरणी जहां मैं जावा वस्तु जोड़ने बनाने की जरूरत .it
{
"storyTitle" : "ttt",
"storyBody" : "tttt",
"storyAuthor" : "tttt"
}
{
"storyTitle" : "a",
"storyBody" : "a",
"storyAuthor" : "a"
}
की तरह डेटा बनाता चाहते हैं, डेटा इस
[{
"storyTitle" : "ttt",
"storyBody" : "tttt",
"storyAuthor" : "tttt"
}
,{
"storyTitle" : "a",
"storyBody" : "a",
"storyAuthor" : "a"
}]
की तरह होना चाहिए
असंबद्ध टिप: यदि फ़ाइल मौजूद नहीं है तो फ़ाइल बनाना आवश्यक नहीं है। बस इसे लिखें। – Henry
'writeValueAsString (कहानी);' क्या आप कोड दिखा सकते हैं जो परिभाषित करता है कि 'कहानी' क्या है? – PDStat
मुझे लिखने का तरीका मिला है मैंने इसे एरे – Sayem