當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONParser.parseStrict方法代碼示例

本文整理匯總了Java中com.google.gwt.json.client.JSONParser.parseStrict方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONParser.parseStrict方法的具體用法?Java JSONParser.parseStrict怎麽用?Java JSONParser.parseStrict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.gwt.json.client.JSONParser的用法示例。


在下文中一共展示了JSONParser.parseStrict方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toList

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
public List<String> toList(String jsonStr) {

    JSONValue parsed = JSONParser.parseStrict(jsonStr);
    JSONArray jsonArray = parsed.isArray();

    if (jsonArray == null) {
      return Collections.emptyList();
    }

    List<String> list = new ArrayList<>();
    for (int i = 0; i < jsonArray.size(); i++) {
      JSONValue jsonValue = jsonArray.get(i);
      JSONString jsonString = jsonValue.isString();
      String stringValue = (jsonString == null) ? jsonValue.toString() : jsonString.stringValue();
      list.add(stringValue);
    }

    return list;
  }
 
開發者ID:eclipse,項目名稱:che-archetypes,代碼行數:20,代碼來源:StringListUnmarshaller.java

示例2: extractFormName

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
private static String extractFormName(RpcResult result) {
  String extraString = result.getExtra();
  if (extraString != null) {
    JSONValue extraJSONValue = JSONParser.parseStrict(extraString);
    JSONObject extraJSONObject = extraJSONValue.isObject();
    if (extraJSONObject != null) {
      JSONValue formNameJSONValue = extraJSONObject.get("formName");
      if (formNameJSONValue != null) {
        JSONString formNameJSONString = formNameJSONValue.isString();
        if (formNameJSONString != null) {
          return formNameJSONString.stringValue();
        }
      }
    }
  }
  return "Screen1";
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:18,代碼來源:WaitForBuildResultCommand.java

示例3: parseGadgetInfoJson

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
@Override
public List<GadgetInfo> parseGadgetInfoJson(String json) {
  List<GadgetInfo> gadgetList = new ArrayList<GadgetInfo>();
  JSONValue value = JSONParser.parseStrict(json);
  JSONArray array = value.isArray();
  if (array != null) {
    for (int i = 0; i < array.size(); i++) {
      JSONValue item = array.get(i);
      GadgetInfo info = parseGadgetInfo(item);
      if (info != null) {
        gadgetList.add(info);
      }
    }
  }
  return gadgetList;
}
 
開發者ID:jorkey,項目名稱:Wiab.pro,代碼行數:17,代碼來源:GwtGadgetInfoParser.java

示例4: toMap

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
public static Map<String, String> toMap(String jsonStr) {
  Map<String, String> map = new HashMap<String, String>();

  JSONValue parsed = JSONParser.parseStrict(jsonStr);
  JSONObject jsonObj = parsed.isObject();
  if (jsonObj != null) {
    for (String key : jsonObj.keySet()) {
      JSONValue jsonValue = jsonObj.get(key);
      JSONString jsonString = jsonValue.isString();
      // if the json value is a string, set the unescaped value, else set the json representation
      // of the value
      String stringValue = (jsonString == null) ? jsonValue.toString() : jsonString.stringValue();
      map.put(key, stringValue);
    }
  }

  return map;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:19,代碼來源:JsonHelper.java

示例5: toMapOfLists

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
public static Map<String, List<String>> toMapOfLists(String jsonStr) {
  Map<String, List<String>> map = new HashMap<>();

  JSONValue parsed = JSONParser.parseStrict(jsonStr);
  JSONObject jsonObj = parsed.isObject();
  if (jsonObj != null) {
    for (String key : jsonObj.keySet()) {
      JSONValue jsonValue = jsonObj.get(key);
      JSONArray jsonArray = jsonValue.isArray();

      List<String> values = new ArrayList<>();
      for (int i = 0; i < jsonArray.size(); i++) {
        values.add(jsonArray.get(i).isString().stringValue());
      }
      map.put(key, values);
    }
  }

  return map;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:21,代碼來源:JsonHelper.java

示例6: deserialize

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
@Override
public Object deserialize(String payload, Type expected)
    throws SerializerException {

    JSONValue jsonValue = JSONParser.parseStrict(payload);

    try {
        Object object = fromJSONValue(jsonValue, expected);

        if (object == null) {
            throw new SerializerException(
                SerializerException.Error.NOT_DESERIALIZABLE);
        }

        return object;

    } catch (NoSuitableSerializableFactory exception) {
        throw new SerializerException(
            SerializerException.Error.NOT_DESERIALIZABLE, exception);
    }
}
 
開發者ID:snogaraleal,項目名稱:wbi,代碼行數:22,代碼來源:JSONSerializer.java

示例7: init

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
public void init() {
	// try to get the serialized representation of the SQLite DB from the
	// local storage
	String serializedDb = storage.getItem(LOCALSTORAGE_KEY_DB);

	if (serializedDb == null || serializedDb.isEmpty()) {
		// if nothing is found, we create the database from scratch
		sqlDb = SQLite.create();

		// and inject the SQL file which creates the tables structure
		DbSchema dbSchema = (DbSchema) GWT.create(DbSchema.class);
		sqlDb.execute(dbSchema.sqlForSchema().getText());
	} else {
		// if the local storage already contains some data, parse it as a
		// JSON integer array
		JSONValue dbContent = JSONParser.parseStrict(serializedDb);

		// and initialize SQLite with this "file"
		sqlDb = SQLite.create(dbContent.isArray().getJavaScriptObject()
				.<JsArrayInteger> cast());
	}

	persistDB();
	getMinIdPasswd();
	getMinIdField();
}
 
開發者ID:guiguib,項目名稱:yaph,代碼行數:27,代碼來源:DataAccess.java

示例8: onResponseReceived

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
public final void onResponseReceived(final Request request, final Response response) {
  final String text = response.getText();
  if (text.isEmpty()) {
    final int code = response.getStatusCode();
    final String errmsg;
    if (code == 0) {  // Happens when a cross-domain request fails to connect.
      errmsg = ("Failed to connect to " + server + ", check that the server"
                + " is up and that you can connect to it.");
    } else {
      errmsg = ("Empty response from server: code=" + code
                + " status=" + response.getStatusText());
    }
    onError(request, new RuntimeException(errmsg));
  } else {
    JSONValue value;
    try {
      value = JSONParser.parseStrict(text);
    } catch (JSONException e) {
      onError(request, e);
      return;
    }
    onSuccess(value);
  }
}
 
開發者ID:tsuna,項目名稱:droopy,代碼行數:25,代碼來源:Main.java

示例9: isValidJSON

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
public boolean isValidJSON(String json) {
    boolean valid = true;
    try {
        JSONParser.parseStrict(json);
    } catch (Exception exc) {
        valid = false;
    }
    return valid;
}
 
開發者ID:YoungDigitalPlanet,項目名稱:empiria.player,代碼行數:10,代碼來源:OverlayTypesParser.java

示例10: onSuccess

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
@Override
        public void onSuccess(String json) {
            /*
             

{
  "table": {
    "columnNames": ["expocode", "vessel_name", "investigators", "qc_flag"],
    "columnTypes": ["String", "String", "String", "String"],
    "columnUnits": [null, null, null, null],
    "rows": [
      ["01AA20110928", "Nuka Arctica", "Truls Johannessen ; Abdirahman Omar ; Ingunn Skjelvan", "N"]
    ]
  }
}             
             
             
             */
            JSONValue jsonV = JSONParser.parseStrict(json);
            JSONObject jsonO = jsonV.isObject();
            if ( jsonO != null) {
                JSONObject table = (JSONObject) jsonO.get("table");
                JSONArray names = (JSONArray) table.get("columnNames");
                JSONArray rows = (JSONArray) table.get("rows");
                JSONArray r0 = (JSONArray) rows.get(0);
                for (int i = 0; i < names.size(); i++) {
                    
                    String name = names.get(i).toString();
                    if  ( name.endsWith("") ) name = name.substring(0,name.length()-1);
                    if  ( name.startsWith("") ) name = name.substring(1,name.length());

                    String value = r0.get(i).toString();
                    if  ( value.endsWith("") ) value = value.substring(0,value.length()-1);
                    if  ( value.startsWith("") ) value = value.substring(1,value.length());
                    
                    metadata.put(name.toUpperCase(Locale.ENGLISH), value);
                }
            }
            showMetadata();
        }
 
開發者ID:NOAA-PMEL,項目名稱:LAS,代碼行數:41,代碼來源:ThumbnailPropProp.java

示例11: onSuccess

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
@Override
public void onSuccess(String json) {

	JSONValue jsonV = JSONParser.parseStrict(json);
	JSONObject jsonO = jsonV.isObject();
	MarkerClustererOptions clusterOptions = MarkerClustererOptions.newInstance();
	clusterOptions.setIgnoreHidden(true);
	MarkerClusterer cluster = MarkerClusterer.newInstance(mapUI.getMap(), clusterOptions);
	List<LatLng> locations = new ArrayList<LatLng>();
	if ( jsonO != null) {
		JSONObject table = (JSONObject) jsonO.get("table");
		JSONValue id = (JSONValue) table.get("catid");
		String catid = id.toString().trim().replace("\"", "");
		JSONArray names = (JSONArray) table.get("columnNames");
		JSONArray rows = (JSONArray) table.get("rows");

		int index = 0;
		for(int i = 1; i < rows.size(); i++) {
			JSONArray row = (JSONArray) rows.get(i);
			String latitude = row.get(0).toString();
			String longitude = row.get(1).toString();
			if ( latitude != null && longitude != null & !latitude.equals("null") && !longitude.equals("null")) {
				LatLng p = LatLng.newInstance(Double.valueOf(latitude), Double.valueOf(longitude));
				MarkerOptions options = MarkerOptions.newInstance();
				options.setPosition(p);
				options.setMap(mapUI.getMap());
				Marker marker = Marker.newInstance(options);
				locations.add(p);
				cluster.addMarker(marker);
			}
			index++;
		}

		mapUI.addMarkerClustererToPanel(catid, cluster);
		mapUI.addLocationsToPanel(catid, locations);
	}
}
 
開發者ID:NOAA-PMEL,項目名稱:LAS,代碼行數:38,代碼來源:Inventory.java

示例12: GWTFileUploadResponse

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
/**
 * GWTFileUploadResponse
 *
 * @param text json encoded parameters.
 */
public GWTFileUploadResponse(String text) {
	text = text.substring(text.indexOf("{"));
	text = text.substring(0, text.lastIndexOf("}") + 1);
	JSONValue responseValue = JSONParser.parseStrict(text);
	JSONObject response = responseValue.isObject();

	// Deserialize information
	hasAutomation = response.get("hasAutomation").isBoolean().booleanValue();
	path = URL.decodeQueryString(response.get("path").isString().stringValue());
	error = response.get("error").isString().stringValue();
	showWizardCategories = response.get("showWizardCategories").isBoolean().booleanValue();
	showWizardKeywords = response.get("showWizardKeywords").isBoolean().booleanValue();
	digitalSignature = response.get("digitalSignature").isBoolean().booleanValue();

	// Getting property groups
	JSONArray groupsArray = response.get("groupsList").isArray();

	if (groupsArray != null) {
		for (int i = 0; i <= groupsArray.size() - 1; i++) {
			groupsList.add(groupsArray.get(i).isString().stringValue());
		}
	}

	// Getting workflows
	JSONArray workflowArray = response.get("workflowList").isArray();

	if (workflowArray != null) {
		for (int i = 0; i <= workflowArray.size() - 1; i++) {
			workflowList.add(workflowArray.get(i).isString().stringValue());
		}
	}
}
 
開發者ID:openkm,項目名稱:document-management-system,代碼行數:38,代碼來源:GWTFileUploadResponse.java

示例13: parseJSON

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
/**
 * Parse a JSON string
 * <p>
 * If the input is not valid JSON or parsing fails for some reason,
 * the exception will be logged in the UI but not thrown.
 * 
 * @param jsonStr a valid JSON string
 * @return a java representation of the JSON object hierarchy,
 *     or a JSONObject representing {} if parsing fails
 */
public JSONValue parseJSON(String jsonStr) {
    try {
        return JSONParser.parseStrict(jsonStr);
    } catch (Throwable t) {
        // only shows up in eclipse dev mode
        t.printStackTrace();

        LogModel.getInstance().logCriticalMessage("JSON Parser failed " + t.getClass().getName() + ": " +
                                                  t.getLocalizedMessage());
        LogModel.getInstance().logCriticalMessage("input was: " + jsonStr);
        return new JSONObject();
    }
}
 
開發者ID:ow2-proactive,項目名稱:scheduling-portal,代碼行數:24,代碼來源:Controller.java

示例14: readPreferencesFromJson

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
private static Map<String, JSONValue> readPreferencesFromJson(String jsonPreferences) {
  Map<String, JSONValue> result = new HashMap<>();
  JSONValue parsed = JSONParser.parseStrict(jsonPreferences);

  JSONObject jsonObj = parsed.isObject();
  if (jsonObj != null) {
    jsonObj.keySet().forEach(key -> result.put(key, jsonObj.get(key)));
  }
  return result;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:11,代碼來源:EditorPreferencesManager.java

示例15: readPropertiesFromJson

import com.google.gwt.json.client.JSONParser; //導入方法依賴的package包/類
private static Map<String, JSONValue> readPropertiesFromJson(String jsonProperties) {
  Map<String, JSONValue> result = new HashMap<>();
  JSONValue parsed = JSONParser.parseStrict(jsonProperties);

  JSONObject jsonObj = parsed.isObject();
  if (jsonObj != null) {
    for (String key : jsonObj.keySet()) {
      JSONValue jsonValue = jsonObj.get(key);
      result.put(key, jsonValue);
    }
  }
  return result;
}
 
開發者ID:eclipse,項目名稱:che,代碼行數:14,代碼來源:EditorPropertiesManager.java


注:本文中的com.google.gwt.json.client.JSONParser.parseStrict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。