forked from martinadamek/json-android-compare
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
76 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/layout" | ||
android:orientation="vertical" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:padding="10dp"> | ||
</LinearLayout> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/layout" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:orientation="vertical" | ||
android:padding="10dp" > | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.martinadamek.jsonandroid; | ||
|
||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.*; | ||
|
||
import net.minidev.json.JSONArray; | ||
import net.minidev.json.JSONObject; | ||
import net.minidev.json.parser.JSONParser; | ||
|
||
public class SmartJson implements TestJson { | ||
|
||
public String getName() { | ||
return "JSON.smart"; | ||
} | ||
|
||
public List<Map> parsePublicTimeline(InputStream inputStream) { | ||
|
||
List<Map> result = new ArrayList<Map>(); | ||
|
||
JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE); | ||
|
||
try { | ||
JSONArray jsonArray = (JSONArray) p.parse(new InputStreamReader(inputStream)); | ||
int size = jsonArray.size(); | ||
|
||
for (int i = 0; i < size; i++) { | ||
Map map = new HashMap(); | ||
JSONObject jsonObject = (JSONObject) jsonArray.get(i); | ||
|
||
Set keys = jsonObject.keySet(); | ||
for (Object key: keys) { | ||
if ("user".equals(key)) { | ||
JSONObject user = (JSONObject) jsonObject.get(key); | ||
Set keys2 = user.keySet(); | ||
for (Object key2: keys2) { | ||
map.put("user." + key2, user.get(key2)); | ||
} | ||
} else { | ||
map.put(key, jsonObject.get(key)); | ||
} | ||
} | ||
|
||
result.add(map); | ||
} | ||
|
||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
return result; | ||
} | ||
} |