json串如何写

 
  
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
< html >
< head >
< title ></ title >
< meta name ="GENERATOR" content ="Microsoft Visual Studio .NET 7.1" >
< meta name =ProgId content =VisualStudio.HTML >
< meta name =Originator content ="Microsoft Visual Studio .NET 7.1" >
< script src =http://www.cnblogs.com/js/jquery-1.4.4.min.js ></ script >
</ head >
< body >
< div id ="count" ></ div >
< script >
/*
$.ajax({
type: "POST",
url: "json.aspx",
data: "id=1",
success: function(msg){
msg = eval(msg);
alert(msg);
}
});
*/
function f(msg)
{
alert(msg.arg1[
0 ].v);
}
// 可以
f({ arg1: [ {v: " 1 " } ]});
// 可以
f({ arg1: [ { " v " : " 1 " } ]});
</ script >

</ body >
</ html >
/* $.ajax({ type: "POST", url: "json.aspx", data: "id=1", success: function(msg){ msg = eval(msg); alert(msg); } }); */ function f(msg) { alert(msg.arg1[0].v); } //可以 f({ arg1: [ {v:"1"} ]}); //可以 f({ arg1: [ {"v":"1"} ]}); // ]]>

转载于:https://www.cnblogs.com/liulf/archive/2011/01/20/1940427.html

在C++中,我们可以使用rapidjson库来生成json字符。下面是一个简单的例子: 1. 首先,我们需要包含rapidjson库的头文件: ``` #include "rapidjson/document.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" ``` 2. 然后,我们需要创建一个rapidjson::Document对象,并获取它的分配器: ``` rapidjson::Document jsonDoc; rapidjson::Document::AllocatorType& allocator = jsonDoc.GetAllocator(); ``` 3. 接下来,我们可以使用jsonDoc对象的方法来设置json对象的各个属性: ``` jsonDoc.SetObject(); // 设置json对象 rapidjson::Value storeArray(rapidjson::kArrayType); // 创建一个数组对象 for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { rapidjson::Value pixelArray(rapidjson::kArrayType); // 创建一个数组对象 pixelArray.PushBack(i+j, allocator); // 添加元素 pixelArray.PushBack(i+j+1, allocator); // 添加元素 storeArray.PushBack(pixelArray, allocator); // 添加元素 } } jsonDoc.AddMember("store", storeArray, allocator); // 添加属性 ``` 4. 最后,我们可以将jsonDoc对象转换为字符并输出: ``` rapidjson::StringBuffer buffer; rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); jsonDoc.Accept(writer); std::string command_string = buffer.GetString(); std::cout << command_string << std::endl; ``` 以上就是一个简单的C++生成json字符的例子。需要注意的是,rapidjson库还提供了很多其他的方法和功能,可以根据具体需求进行使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值