Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] JSON Array 처리기 추가 #14

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Add json array process function on Android

  • Loading branch information
hwshim0810 committed May 3, 2019
commit 8dc31e0815b6ce5013e373da5677f711f5be0422
@@ -10,12 +10,14 @@
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.ReadableType;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

@@ -130,6 +132,9 @@ private JSONObject toJSONObject(ReadableMap data) { // https://gist.github.com/m
case Map: // nested object recursive하게 처리
jsonObject.put(key, toJSONObject(data.getMap(key)));
break;
case Array:
jsonObject.put(key, toJSONArray(data.getArray(key)));
break;
default :
jsonObject.put(key, data.getMap(key));
break;
@@ -142,6 +147,44 @@ private JSONObject toJSONObject(ReadableMap data) { // https://gist.github.com/m
return jsonObject;
}

private JSONArray toJSONArray(ReadableArray data) {
JSONArray jsonArray = new JSONArray();

try {
for (int i = 0; i < data.size(); i++) {
ReadableType type = data.getType(i);

switch (type) {
case Null:
jsonArray.put(i, null);
break;
case Boolean:
jsonArray.put(i, data.getBoolean(i));
break;
case Number:
jsonArray.put(i, data.getDouble(i));
break;
case String:
jsonArray.put(i, data.getString(i));
break;
case Map:
jsonArray.put(i, toJSONObject(data.getMap(i)));
break;
case Array:
jsonArray.put(i, toJSONArray(data.getArray(i)));
break;
default:
jsonArray.put(i, toJSONArray(data.getArray(i)));
break;
}
}
} catch (JSONException e) {

}

return jsonArray;
}

/* url이 https, http 또는 javascript로 시작하는지 체크 */
private boolean isUrlStartsWithProtocol(String url) {
if (url.startsWith("https://") || url.startsWith("http://") || url.startsWith("javascript:")) return true;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.