我有一些JSON已经从servlet传递并存储在xmlhttp.responseText中.我想分解这个JSON,以便我可以拥有数据,大小,样式,名称等的值.此外,我希望将窗口小部件值放在单独的变量中.
这是JSON:
{
"widget vlaue=2": {
"debug": "on",
"window": {
"title": "Sample Konfabulator Widget",
"name": "main_window",
"width": 500,
"height": 500
},
},
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center"
},
"text": {
"data": "Click Here",
"size": 36,
"style": "bold",
"name": "text1",
"hOffset": 250,
"vOffset": 100,
"alignment": "center",
"onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
}
}
Run Code Online (Sandbox Code Playgroud)
我试过这个:
obj = JSON.parse(xmlhttp.responseText);
Run Code Online (Sandbox Code Playgroud)
但这失败了.我在网上找不到与之相关的任何内容.有人可以帮我这个吗?
我有一个像这样的字符数组:
+---+---+---+ |53.|.7.|...| |6..|195|...| |.98|...|.6.| +---+---+---+
我使用int数组来存储特定索引处的特定值.对于转换我用过
for(int i=0;i<27;i++)
{
inputNumArray[i]=atoi(&inputInitial[indexArray[i]]);
}
Run Code Online (Sandbox Code Playgroud)
现在问题是我想要的出局是:
5 3 0 0 7 0 0 0 0 6 0 0 1 9 5 0 0 0 0 9 8 0 0 0 0 6 0
并且代码返回给我:
53 3 0 0 7 0 0 0 0 6 0 0 195 95 5 0 0 0 0 98 8 0 0 0 0 6 0
我假设原因是atoi扫描直到它找到字符并且对于atoi(&inputInitial [i])它将读取直到i + 1,i + 2 ......依此类推,直到遇到错误.我想将atoi扫描限制为单个字符.是否有可能或者我应该使用其他功能?
我试图从我的服务器上的网页获取数据.但是,当我运行此代码时,它始终在httpClient.execute()失败
String flixURL=("http://myserver.com:6718/cgi-bin/log.pl?zip=" + zippy);
Toast.makeText(getBaseContext(),flixURL,5).show();
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(flixURL);
ResponseHandler<String> resHandler = new BasicResponseHandler();
System.out.println("resHandler"+resHandler);
try {
String page = httpClient.execute(httpGet, resHandler);
System.out.println("page"+page);
}
catch (ClientProtocolException e)
{
e.printStackTrace();System.out.println(e);
}
catch (IOException e) {
e.printStackTrace();System.out.println(e);
}
Run Code Online (Sandbox Code Playgroud)
调试器告诉我可能是UnknownHostException.我已尝试过不同的URL,但问题仍然存在.
Android Manifest文件如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.andtwi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="@string/app_name"
android:name=".AndTwitterActivity" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".screen2" android:label="Screen2">
</activity> …Run Code Online (Sandbox Code Playgroud) 我有两个文件,XML和HTML,需要从某些模式中提取数据.
我的XML文件格式很好,我可以使用readline读取一行并在标签之间搜索数据.
if($line =~ /\<tag1\>$varvalue\<\/tag1\>/)`
Run Code Online (Sandbox Code Playgroud)
但是,对于我的HTML,它有一个我见过的最糟糕的代码,文件是这样的:
<div class="theater">
<h2>
<a href="/showtimes/university-village-3" >**University Village 3**</a></h2>
<div class="address">
<i>**3323 South Hoover Street, Los Angeles CA 90007 | (213) 748-6321**</i>
</div>
</div>
<div class="mtitle">
<a href="/movie/dream-house-2011" title="Dream House" onmouseover="mB(event, 771204354);" >**Dream House**</a>
<span>**(PG-13 , 1 hr. 31 min.)**</span>
</div>
<div class="times">
**1:00 PM,**
</div>
Run Code Online (Sandbox Code Playgroud)
现在从这个文件我需要选择以粗体显示的数据.
我可以使用Perl正则表达式来搜索此文件中的数据.
执行我的Android应用程序时出现此错误:
Host is unresolved: api.twitter.com:80
Relevant discussions can be on the Internet at:
http://www.google.co.jp/search?q=10f5ada3 or
http://www.google.co.jp/search?q=dceba048
TwitterException{exceptionCode=[10f5ada3-dceba048 10f5ada3-dceba01e], statusCode=-1, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.5}
Run Code Online (Sandbox Code Playgroud)
虽然我已经设置了适当的权限..这是我的代码:
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abc"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:label="test1"
android:name=".A1Activity"
android:launchMode="singleTask">
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="twitterapp" android:host="callback" />
</intent-filter>
</activity>
<activity class=".screen2" android:label="test2" android:name=".screen2">
</activity>
</application>
</manifest> …Run Code Online (Sandbox Code Playgroud) Screen2.java文件具有以下代码:
public class screen2 extends Activity {
public int globalZip=0;
//Some validations & update globalZip
//Code control goes to Screen3,java
}
Run Code Online (Sandbox Code Playgroud)
Screen3.java文件具有以下代码:
public class Screen3 extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen3);
screen2 objs2= new screen2();
int myzip = objs2.globalZip;
Toast.makeText(getBaseContext(), "Screen3 "+myzip, 5).show();
System.out.println("WTHDude"+"Screen3 "+myzip);
}
Run Code Online (Sandbox Code Playgroud)
现在我遇到的问题是,如果我在Screen2.java文件中将globalZip的值更新为90034,则不会在screen3中更新.任何人都可以帮我解决这个错误.谢谢.
我有一个字符串"上午11:45,下午12:30,下午04:50"
我希望使用java regex从这个字符串中第一次提取.
我创建了一个java正则表达式:
"\ d*\S\d*\s(AM | PM)"为此.
但是我只能在Java中匹配这种模式而不是提取它.如何使用我创建的正则表达式提取第一个令牌