JSON解析URI+;文本框
我需要从uriff解析JSON,如上面的示例 内置URI(后跟JSON解析URI+;文本框,json,Json,我需要从uriff解析JSON,如上面的示例 内置URI(后跟textbox1; 只有textbox1的值会更改 它可以是Android、JavaScript等。你的问题太宽泛了,但我将发布一个带有PHP/JQUERY/JS/AJAX/
textbox1
;
只有textbox1
的值会更改
它可以是Android、JavaScript等。你的问题太宽泛了,但我将发布一个带有PHP/JQUERY/JS/AJAX/
在文档根目录中创建
.htaccess
文件/
此重写规则将使友好的URL/doctracklog/{some value}
工作
http://example.com/doctracklog/20140827091936
在文档根/(JS-JQUERY-AJAX)中创建
doctracklog.php
文件
此代码将读取json对象并显示特定错误的用户信息
Options Indexes FollowSymLinks
RewriteEngine on
RewriteRule doctracklog/(.*)/? doctracklog.php?id=$1
测试用例: 以下是一些可能的例子 没有Id: 错误的Id: 右侧Id:
结果 这些是示例的结果
请查看附件中的图片,非常感谢Lea Tano的输入,我希望你能看到这篇文章并给我一些反馈谢谢。@aqie当然,请附上有问题的文件,并用你的话解释一下这张表格应该做什么。查看附件中的图片,我想制作一个android应用程序,它将聚合给出的信息有足够的json文件,我想获得最新的信息。日志和最近的日期。文本框doctrack#。用户将在其中输入他们的14位控制编号。我希望您理解我的问题。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example</title>
<!-- javascript/jQuery -->
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<div id="holder"></div>
</head>
<body>
<script>
$.ajax({
url: '/json.php',
type: 'POST',
data: {
'id': '<?php echo !empty($_GET['id']) ? $_GET['id'] : "";?>'
},
success: function (response) {
if (response.status !== 'Error') {
console.log(response);
alert(response.user.name + "-" + response.user.age + "-" + response.user.gender);
} else {
alert(response.message);
}
},
error: function () {
alert("error");
}
});
</script>
</body>
</html>
<?php
//this is the number you are passing in your URI. For ex. http://example.com/doctracklog/20140827091936
$userId = $_POST['id'] ? $_POST['id'] : "";
//This is a dummy array example, so we can use userId as its index
if(!empty($userId)) {
$users = array(
'20140827091936' => array(
'name' => 'John',
'age' => '20',
'gender' => 'male'
),
'20140920081120' => array(
'name' => 'Susan',
'age' => '32',
'gender' => 'female'
)
);
if(array_key_exists($userId,$users)) {
$json = array('status' => 'OK', 'user' => $users[$userId]);
} else {
$json = array('status' => 'Error','message' => 'Id does not exist');
}
} else {
$json = array('status' => 'Error','message' => 'You did not pass any id');
}
//return json object
header('Content-Type: application/json');
echo json_encode($json);