Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4d86b05

Browse files
stringToValue
1 parent34f327e commit4d86b05

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

‎XML.java

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ of this software and associated documentation files (the "Software"), to deal
3131
* This provides static methods to convert an XML text into a JSONObject,
3232
* and to covert a JSONObject into an XML text.
3333
* @author JSON.org
34-
* @version2012-10-26
34+
* @version2013-11-12
3535
*/
3636
publicclassXML {
3737

@@ -301,9 +301,6 @@ private static boolean parse(XMLTokener x, JSONObject context,
301301
* @return A simple JSON value.
302302
*/
303303
publicstaticObjectstringToValue(Stringstring) {
304-
if ("".equals(string)) {
305-
returnstring;
306-
}
307304
if ("true".equalsIgnoreCase(string)) {
308305
returnBoolean.TRUE;
309306
}
@@ -313,36 +310,26 @@ public static Object stringToValue(String string) {
313310
if ("null".equalsIgnoreCase(string)) {
314311
returnJSONObject.NULL;
315312
}
316-
if ("0".equals(string)) {
317-
returnnewInteger(0);
318-
}
319313

320-
// If it might be a number, try converting it. If that doesn't work,
321-
// return the string.
314+
// If it might be a number, try converting it, first as a Long, and then as a
315+
//Double. If that doesn't work,return the string.
322316

323317
try {
324318
charinitial =string.charAt(0);
325-
booleannegative =false;
326-
if (initial =='-') {
327-
initial =string.charAt(1);
328-
negative =true;
329-
}
330-
if (initial =='0' &&string.charAt(negative ?2 :1) =='0') {
331-
returnstring;
332-
}
333-
if ((initial >='0' &&initial <='9')) {
334-
if (string.indexOf('.') >=0) {
335-
returnDouble.valueOf(string);
336-
}elseif (string.indexOf('e') <0 &&string.indexOf('E') <0) {
337-
LongmyLong =newLong(string);
338-
if (myLong.longValue() ==myLong.intValue()) {
339-
returnnewInteger(myLong.intValue());
340-
}else {
341-
returnmyLong;
342-
}
319+
if (initial =='-' || (initial >='0' &&initial <='9')) {
320+
Longvalue =newLong(string);
321+
if (value.toString().equals(string)) {
322+
returnvalue;
343323
}
344324
}
345325
}catch (Exceptionignore) {
326+
try {
327+
Doublevalue =newDouble(string);
328+
if (value.toString().equals(string)) {
329+
returnvalue;
330+
}
331+
}catch (ExceptionignoreAlso) {
332+
}
346333
}
347334
returnstring;
348335
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp