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

Commit1f7056e

Browse files
author
Douglas Crockford
committed
kensenjohn
1 parent1a85fe7 commit1f7056e

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

‎Property.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
packageorg.json;
2+
3+
/*
4+
Copyright (c) 2002 JSON.org
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
The Software shall be used for Good, not Evil.
17+
18+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24+
SOFTWARE.
25+
*/
26+
27+
importjava.util.Enumeration;
28+
importjava.util.Iterator;
29+
importjava.util.Properties;
30+
31+
/**
32+
* Converts a Property file data into JSONObject and back.
33+
* @author JSON.org
34+
* @version 2013-05-23
35+
*/
36+
publicclassProperty {
37+
/**
38+
* Converts a property file object into a JSONObject. The property file object is a table of name value pairs.
39+
* @param properties java.util.Properties
40+
* @return JSONObject
41+
* @throws JSONException
42+
*/
43+
publicstaticJSONObjecttoJSONObject(java.util.Propertiesproperties)throwsJSONException {
44+
JSONObjectjo =newJSONObject();
45+
if (properties !=null && !properties.isEmpty()) {
46+
EnumerationenumProperties =properties.propertyNames();
47+
while(enumProperties.hasMoreElements()) {
48+
Stringname = (String)enumProperties.nextElement();
49+
jo.put(name,properties.getProperty(name));
50+
}
51+
}
52+
returnjo;
53+
54+
}
55+
56+
/**
57+
* Converts the JSONObject into a property file object.
58+
* @param jo JSONObject
59+
* @return java.util.Properties
60+
* @throws JSONException
61+
*/
62+
publicstaticPropertiestoProperties(JSONObjectjo)throwsJSONException {
63+
Propertiesproperties =newProperties();
64+
if (jo !=null) {
65+
Iteratorkeys =jo.keys();
66+
67+
while (keys.hasNext()) {
68+
Stringname =keys.next().toString();
69+
properties.put(name,jo.getString(name));
70+
}
71+
}
72+
returnproperties;
73+
}
74+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp