我有以下JSON字符串:
{
"ms": "images,5160.1",
"turl": "http://ts1.mm.bing.net/th?id=I4693880201938488&pid=1.1",
"height": "178",
"width": "300",
"imgurl": "http://www.attackingsoccer.com/wp-content/uploads/2011/07/World-Cup-2012-Draw.jpg",
"offset": "0",
"t": "World Cup 2014 Qualification – Europe Draw World Cup 2012 Draw ...",
"w": "719",
"h": "427",
"ff": "jpeg",
"fs": "52",
"durl": "www.attackingsoccer.com/2011/07/world-cup-2012-qualification-europe...",
"surl": "http://www.attackingsoccer.com/2011/07/world-cup-2012-qualification-europe-draw/world-cup-2012-draw/",
"mid": "D9E91A0BA6F9E4C65C82452E2A5604BAC8744F1B",
"k": "6",
"ns": "API.images"
}
Run Code Online (Sandbox Code Playgroud)
我需要将值存储imgurl
在单独的字符串中.
这就是我现在所拥有的,但这只是给了我整个JSON字符串而不是特定的imgurl字段.
Gson gson = new Gson();
Data data = new Data();
data = gson.fromJson(toExtract, Data.class);
System.out.println(data);
Run Code Online (Sandbox Code Playgroud)
toExtract
是JSON字符串.这是我的数据类:
public class Data
{
public List<urlString> myurls;
}
class urlString
{
String imgurl; …
Run Code Online (Sandbox Code Playgroud) 我看了很多不同的帖子,但是他们都在使用不同版本的django,或者似乎没有用.这是我正在尝试做的事情:
urls.py(适用于整个项目):
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^blog/', include('blog.urls', namespace="blog")),
url(r'^admin/', include(admin.site.urls)),
)
Run Code Online (Sandbox Code Playgroud)
urls.py(特定于应用程序):
urlpatterns = patterns ('' ,
url(r'^$', views.index, name='index'),
url(r'^(?P<slug>[\w\-]+)/$', views.posts, name="postdetail"),
)
Run Code Online (Sandbox Code Playgroud)
views.py:
def index(request):
posts = Post.objects.filter(published=True)
return render(request,'blog/index.html',{'posts':posts})
def posts(request, slug):
post = get_object_or_404(Post,slug=slug)
return render(request, 'blog/post.html',{'post':post})
Run Code Online (Sandbox Code Playgroud)
最后是模板:
{% block title %} Blog Archive {% endblock %}
{% block content %}
<h1> My Blog Archive </h1>
{% for post in posts %}
<div class="post">
<h2>
<a href="{% url "postdetail" slug=post.slug %}"> …
Run Code Online (Sandbox Code Playgroud) 查看问题标题.唯一的另一个限制是较小的矩形必须通过将较大的矩形潜入一半而形成.我已将结果附加到n = 3和n = 4以下.希望这足以解释我的问题的含义.
目前,我有一个低效的递归算法,可以水平和垂直地划分每个矩形,并跟踪数组中所有可能的组合.我不喜欢这个算法.它是多项式时间,似乎不必要的复杂并给我重复,如n = 4图片中所示(提示:寻找四个相等的象限)
我想知道是否有更好的解决方案吗?我正在尝试使用4-ary树(每个孩子得到一个垂直或水平的部分),并且能够构建树,但从树中获得所有可能的组合似乎是在逃避我.我将在下面发布我的树锅炉板代码:
class Node:
#value is an tuple (x0,y0,x1,y1)
def __init__(self, value):
self.horizontal = []
self.vertical = []
self.value = value
def createTree(depth, currDepth, node):
if currDepth == depth:
return
node.horizontal.append(Node(getLeftRect(node.value)))
node.horizontal.append(Node(getRightRect(node.value)))
node.vertical.append(Node(getTopRect(node.value)))
node.vertical.append(Node(getBotRect(node.value)))
createTree(depth, currDepth+1, node.horizontal[0])
createTree(depth, currDepth+1, node.horizontal[1])
createTree(depth, currDepth+1, node.vertical[0])
createTree(depth, currDepth+1, node.vertical[1])
Run Code Online (Sandbox Code Playgroud)
欢迎任何建议/帮助!
注意:这不是课程作业.我正在尝试为我正在开发的自定义虚拟监视器工具创建UI.
我的教授说,建议使用PIT而不是RTC来实现基于纪元的循环调度程序.他没有真正提到任何具体原因,我也想不出任何理由.有什么想法吗?
当我尝试编译以下C代码时,我得到一个总线错误.我猜它与我称之为memcpy的方式有关,但我无法弄明白.任何帮助将不胜感激!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *p = (char*)malloc(sizeof(char)*11);
// Assign some value to p
p = "hello";
char *name = (char*)malloc(sizeof(char)*11);
// Assign some value to name
name = "Bye";
memcpy (p,name,sizeof(char)*10); // Problem begins here
return 0;
}
Run Code Online (Sandbox Code Playgroud) 以下代码返回错误说: "constructor call must be the first statment in a constructor."
我不懂.我的代码中的构造函数是第一个语句.我究竟做错了什么?
public class labelsAndIcons extends JFrame
{
public labelFrame()
{
super( "Testing JLabel" );
}
}
Run Code Online (Sandbox Code Playgroud) 我只是想写入目标 C 中的 .txt 文件。这是代码:
BOOL success = [str writeToFile:@"tmp/cool.txt" atomically:YES encoding:NSUTF8StringEncoding error:&error];
if(success)
{
NSLog(@"done writing!");
}
else
{
NSLog(@"writing failed: %@", [error localizedDescription]);
}
Run Code Online (Sandbox Code Playgroud)
此代码的输出是“文件夹cool.txt 不存在”。我不明白这一点,因为“.txt”会认为它是文件。
我究竟做错了什么?
java ×2
algorithm ×1
bus ×1
c ×1
constructor ×1
django ×1
gson ×1
json ×1
objective-c ×1
optimization ×1
osdev ×1
parsing ×1
python ×1