-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSONOperations.java
More file actions
55 lines (39 loc) · 1.22 KB
/
JSONOperations.java
File metadata and controls
55 lines (39 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.testSel;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Map.Entry;
import java.util.Set;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class JSONOperations
{
public void reverseString(String input)
{
String splitArr[] = input.split(" ");
String revString ="" ;
for(String str:splitArr)
{
String revChar = "";
int len = str.length();
for(int i=len-1 ; i>=0 ; i--)
{
revChar =revChar+str.charAt(i);
}
revString = revString + revChar +" " ;
}
System.out.println("print reverse string:- "+revString);
}
public static void main(String[] args) throws IOException
{
File file = new File("jsonfile.json");
//Read the JSON file and convert it into a String object
String trgrt = new String(Files.readAllBytes(file.toPath()));
//parse the string and convert it into a set object
@SuppressWarnings("deprecation")
JsonObject parser = (JsonObject) new JsonParser().parse(trgrt);
Set<Entry<String, JsonElement>> set = parser.entrySet();
System.out.println(set);
}
}